Sort by

recency

|

2212 Discussions

|

  • + 0 comments
    def breakingRecords(scores):
        # Write your code here
        if len(scores)==1:
            return 0, 0
        else:
            max_val, min_val = scores[0], scores[0]
            max_count, min_count = 0, 0
            for score in scores[1:]:
                if score > max_val:
                    max_val = score
                    max_count += 1
                elif score < min_val:
                    min_val = score
                    min_count += 1
                else:
                    max_count += 0
                    min_count += 0
        return max_count, min_count
    
  • + 0 comments

    python 3

    def breakingRecords(scores): least_score = scores[0] best_score = scores[0]

    best = 0
    least = 0
    
    
    for i in range(1,len(scores)):
        if scores[i] > best_score:
            best_score = scores[i]
            best += 1
        elif scores[i] < least_score:
            least_score = scores[i]
            least +=1
    
    return(best,least)
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/vnovwmHPVXE

    vector<int> breakingRecords(vector<int> scores) {
        int lowest = scores[0], highest = scores[0], lowestCount = 0, highestCount = 0;
        for(int score: scores){
            if(score < lowest){lowestCount++; lowest = score;}
            if(score > highest){highestCount++; highest = score;}
        }
        return {highestCount, lowestCount};
    }
    
  • + 0 comments
    def breakingRecords(scores):
        
        max_score = min_score = scores[0]
        
        high = 0
        low = 0
        
        for i in scores:
            
            if i > max_score:
                
                high += 1
                max_score = i
                
            if i < min_score:
                
                low += 1
                min_score = i
                
        return [high, low]
    
  • + 0 comments

    Solution in JS

    function breakingRecords(scores) {
        let lowestScore = scores[0]
        let highestScore = scores[0]
        let highestScoreBeatenCount = 0;
        let lowestScoreBeatenCount = 0;
        for (let i = 0; i< scores.length; i++){
               if(scores[i] > highestScore){
                    highestScoreBeatenCount+=1
                    highestScore = scores[i]
               }else if (scores[i] < lowestScore){
                    lowestScoreBeatenCount+=1
                    lowestScore = scores[i]
               }
        }
        return [highestScoreBeatenCount,lowestScoreBeatenCount ]
    }