Breaking the Records

Sort by

recency

|

200 Discussions

|

  • + 0 comments
    def breakingRecords(scores):
        count_max=count_min=0
        minimum=maximum=scores[0]
        for i in range(1,len(scores)):
            if scores[i]<minimum:
                count_min+=1
                minimum=scores[i]
            if scores[i]>maximum:
                count_max+=1
                maximum=scores[i]
        array_break=[count_max, count_min]
        return array_break
    
  • + 0 comments
    public static List<Integer> breakingRecords(List<Integer> scores) {
    // Write your code here
        int minimun = scores.get(0);
        int maximun = scores.get(0);
        int min = 0;
        int max = 0;
    
        for (Integer integer : scores) {
            if (integer < minimun) {
                minimun = integer;
                min++;
            }
            if (integer > maximun) {
                maximun = integer;
                max++;
            }
        }
        Integer[] resultado = {max, min};       
        return Arrays.asList(resultado);
    }
    
  • + 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;
    
    }
    

    }