We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Breaking the Records
Breaking the Records
+ 0 comments c++
int contMin=0; int contMax=0; int mayor=scores[0], menor=scores[0]; vector<int> nuevoV; for(int i=0;i<scores.size();i++){ if(scores[i]>mayor){ mayor=scores[i]; contMax++; } if(scores[i]<menor){ menor=scores[i]; contMin++; } } nuevoV.push_back(contMax); nuevoV.push_back(contMin); return nuevoV;
+ 0 comments My js solution
function breakingRecords(scores) { // Write your code here let max = 0, min = 0; let lowest = scores[0],highest = scores[0]; for (let i = 0; i < scores.length; i++) { if(scores[i] > highest){ highest = scores[i]; max++; } if(scores[i] < lowest){ lowest = scores[i]; min++; } } return [max, min]; }
+ 0 comments my java solution
List<Integer> b = new ArrayList<>(); int hscore=scores.get(0),lscore=scores.get(0); int hcount=0,lcount=0; for(int i=1;i<scores.size();i++){ if(scores.get(i)>hscore){ hscore=scores.get(i); if(hscore>=scores.get(i)){ hcount++; } else{ continue; } } if(scores.get(i)<lscore){ lscore=scores.get(i); if(lscore<=scores.get(i)){ lcount++; } else{ continue; } } } b.add(hcount); b.add(lcount); return b; } }
+ 0 comments This is the code in JavaScript ** **All the suggestions are highly appreciated
function breakingRecords(scores) { let turn = 0; let minScore = 0; let maxScore = 0; let highRec = 0; let lowRec = 0; let result = []; for(let i of scores){ if(turn == 0){ minScore = i; maxScore = i; turn += 1; // console.log('turn increased by 1 and setted initial scores',i); } else{ if(i>maxScore){ // console.log(`the maxScore was ${maxScore} and i is ${i} `) maxScore = i; highRec += 1; // console.log(`the maxScore is ${maxScore} setted equal to i ${i} `) } else if(i<minScore){ // console.log(`the minScore was ${minScore} and i is ${i} `) minScore = i; lowRec += 1; // console.log(`the minScore is setted to ${minScore} equal to i ${i} `) } } } result.push(highRec); result.push(lowRec); return result }
+ 0 comments def breakingRecords(scores): # Write your code here max1=[] min1=[] cmax=cmin=0 h=[] l=[] for i in scores: max1.append(i) min1.append(i) h.append(max(max1)) l.append(min(min1)) for i in range(len(h)-1): if h[i]!=h[i+1]: cmax+=1
if l[i]!=l[i+1]: cmin+=1 return cmax,cmin
Load more conversations
Sort 1848 Discussions, By:
Please Login in order to post a comment