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 def breakingRecords(scores): # Write your code here highest_score = [] lowest_score = [] for game, score in enumerate(scores): if game == 0: highest_score.insert(game,score) lowest_score.insert(game,score) else: highest_score.insert(game, score) if score > highest_score[game - 1] else highest_score.insert(game, highest_score[game - 1]) lowest_score.insert(game, score) if score < lowest_score[game - 1] else lowest_score.insert(game, lowest_score[game - 1]) result =[ len([value for index, value in enumerate(highest_score) if index > 0 and value > highest_score[index - 1]]), len([value for index, value in enumerate(lowest_score) if index > 0 and value < lowest_score[index - 1]]) ] return result
+ 0 comments JAVA Code
// Write your code here ArrayList<Integer> max_lst = new ArrayList<Integer>(); ArrayList<Integer> min_lst = new ArrayList<Integer>(); max_lst.add(scores.get(0)); min_lst.add(scores.get(0)); int max_ct = 0; int min_ct = 0; ArrayList<Integer> ans_lst = new ArrayList<Integer>(); for(int i = 1;i<scores.size();i++){ if(max_lst.get(i-1)>scores.get(i)) max_lst.add(max_lst.get(i-1)); else max_lst.add(scores.get(i)); } for(int i = 1;i<scores.size();i++){ if(min_lst.get(i-1)>scores.get(i)) min_lst.add(scores.get(i)); else min_lst.add(min_lst.get(i-1)); }
for(int i = 1;imax_lst.get(i-1)) max_ct++; }
for(int i = 1;i<scores.size();i++){ if(min_lst.get(i)<min_lst.get(i-1)) min_ct++; } ans_lst.add(max_ct); ans_lst.add(min_ct); return ans_lst; }
}
+ 0 comments public static List breakingRecords(List scores) { // Write your code here ArrayList max_lst = new ArrayList(); ArrayList min_lst = new ArrayList(); max_lst.add(scores.get(0)); min_lst.add(scores.get(0)); int max_ct = 0; int min_ct = 0; ArrayList ans_lst = new ArrayList();
for(int i = 1;i<scores.size();i++){ if(max_lst.get(i-1)>scores.get(i)) max_lst.add(max_lst.get(i-1)); else max_lst.add(scores.get(i)); } for(int i = 1;i<scores.size();i++){ if(min_lst.get(i-1)>scores.get(i)) min_lst.add(scores.get(i)); else min_lst.add(min_lst.get(i-1)); }
for(int i = 1;imax_lst.get(i-1)) max_ct++; }
for(int i = 1;i<scores.size();i++){ if(min_lst.get(i)<min_lst.get(i-1)) min_ct++; } ans_lst.add(max_ct); ans_lst.add(min_ct); return ans_lst; }
}
+ 0 comments Here is problem solution in Python Java C++ and C programming - https://programs.programmingoneonone.com/2021/03/hackerrank-breaking-the-records-solution.html
+ 0 comments python code
def breakingRecords(scores): # Write your code here j=0 hs=[scores[j]] ls=[scores[j]] i=1 while i<len(scores): if scores[i]>hs[len(hs)-1]: hs+=[scores[i]] elif scores[i]<ls[len(ls)-1]: ls+=[scores[i]] i+=1 print(len(hs)-1,end=' '),print(len(ls)-1) n = int(input().strip()) scores = list(map(int, input().rstrip().split())) breakingRecords(scores)
Load more conversations
Sort 1992 Discussions, By:
Please Login in order to post a comment