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
+ 16 comments My java submission:
static int[] getRecord(int[] s) { int highest, lowest; highest = lowest = s[0]; int[] result = new int[2]; for (int s_i = 1; s_i < s.length; s_i++) { if (s[s_i] > highest) { highest = s[s_i]; ++result[0]; } else if (s[s_i] < lowest) { lowest = s[s_i]; ++result[1]; } } return result; }
+ 15 comments Here is Python 3 solution from my HackerrankPractice repository:
def breaking_records(score): min = max = score[0] min_count = max_count = 0 for i in score[1:]: if i > max: max_count += 1 max = i if i < min: min_count += 1 min = i return max_count, min_count n = int(input()) score = list(map(int, input().split())) print(*breaking_records(score))
Feel free to ask if you have any questions :)
+ 2 comments JavaScript
// Preparing variables let [ hi, lo ] = [ scores[0], scores[0] ]; let [ max, min ] = [ 0, 0 ]; // Calculating for (let i = 1; i < scores.length; i++) { if (scores[i] > hi) { hi = scores[i]; max++; } if (scores[i] < lo) { lo = scores[i]; min++; } } //Returning return [ max, min ];
+ 2 comments My code is working properly in editor, but i'm getting error here , "result.join() is not a function". Code language Javascript.
+ 2 comments int* breakingRecords(int scores_count, int* scores, int* result_count) { int* a=(int*)malloc(2*sizeof(int)); int highcount=0,lowcount=0,max,min; max=scores[0]; min=scores[0]; for(int i=1;i<scores_count;i++) { if(scores[i]>max) {max=scores[i]; highcount+=1;} if(scores[i]<min) {min=scores[i]; lowcount+=1;} } a[0]=highcount; a[1]=lowcount; *result_count=2; return a; }
Load more conversations
Sort 1587 Discussions, By:
Please Login in order to post a comment