Breaking the Records

Sort by

recency

|

198 Discussions

|

  • + 0 comments

    Using javaScript: let max = scores[0]; let min = scores[0];

    let maxBreak = scores.reduce((result, curr) => {
        if(max < curr){
         result += 1; 
         max = curr; 
        }
        return result;
    }, 0); 
    
    let minBreak = scores.reduce((result, curr) => {
        if(min > curr){
         result += 1; 
         min = curr; 
        }
        return result;
    }, 0); 
    
    return [maxBreak, minBreak];
    

    }

    console.log(breakingRecords([12, 24, 10, 24]))

  • + 0 comments

    Using C++

    vector breakingRecords(vector scores) {

    vector<int> ans;
    int minCount = 0;
    int maxCount = 0;
    int maxi = scores[0];
    int mini = scores[0];
    
    for(int i = 1; i<scores.size(); i++){
    
        if(scores[i] == maxi || scores[i] == mini){
    
        }
    
        else if(maxi > scores[i]){
    
            maxCount++;
            maxi = scores[i];
        }
        else if (mini < scores[i]){
    
            minCount++;
            mini = scores[i];
        }
    }
    
    ans.push_back(minCount);
    ans.push_back(maxCount);
    
    return ans;
    

    }

  • + 0 comments

    Simple solution using Java 15

    public static List<Integer> breakingRecords(List<Integer> scores) {
    // Write your code here
    List<Integer> result = new ArrayList<Integer>(2);
    result.add(0);
    result.add(0);
    int min = scores.get(0);
    int max = scores.get(0);
    for(int i=0; i<scores.size();i++){
        if(scores.get(i)<min){
            min = scores.get(i);
            result.set(1, result.get(1)+1);
        }
        if(scores.get(i)>max){
            max = scores.get(i);
            result.set(0, result.get(0)+1);
        }
    }
    return result;
    
    }
    

    }

  • + 0 comments

    my java solution :

        public static List<Integer> breakingRecords(List<Integer> scores) {
            int n = scores.size();
            int min = scores.get(0), max = scores.get(0);
            int maxCounter = 0, minCounter = 0;
            List<Integer> output = new ArrayList<>(2);
            for (int i = 1 ; i < n ; i++) {
                if(scores.get(i) > max) {
                    maxCounter++;
                    max = scores.get(i);
                } else if(scores.get(i) < min) {
                    minCounter++;
                    min = scores.get(i);
                }
            }
            output.add(maxCounter);
            output.add(minCounter);
            return output;
            
        }
    
  • + 0 comments

    Python Solution:

    def breakingRecords(scores): # Write your code here min_count = 0 max_count = 0 min_score = scores[0] max_score = scores[0]

    for score in scores:
        if min_score < score:
            min_score = score
            min_count += 1
        elif max_score > score:
            max_score = score
            max_count += 1
    
    return [min_count, max_count]