Sort by

recency

|

2196 Discussions

|

  • + 0 comments

    Python min_con, max_con = 0, 0 least_scr, most_scr = scores[0], scores[0] for i in scores: if i < least_scr: min_con += 1 least_scr = i elif i > most_scr : max_con += 1 most_scr = i else: continue

    return max_con, min_con
    
  • + 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

    JavaScript Solution:

        let min = scores[0]
        let max = scores[0]
        let fmin = 0;
        let fmax = 0;
        scores.forEach((score) => {
            if (score < min) {
                fmin += 1
                min = score
            } else if (score > max) {
                fmax += 1
                max = score
            }
        })
        return [fmax, fmin]
    }
    
  • + 0 comments

    With Reduce in JS/Javascript:-

    function breakingRecords(scores) {
        const { minScoreCount, maxScoreCount } = scores.reduce((acc, score) => {
            if (acc.lastMinScore > score) { acc.minScoreCount++; acc.lastMinScore = score; }
            else if (acc.lastMaxScore < score) { acc.maxScoreCount++; acc.lastMaxScore = score; }
            return acc;
        }, {
            lastMinScore: scores[0],
            lastMaxScore: scores[0],
            minScoreCount: 0,
            maxScoreCount: 0,
        });
    
        return [maxScoreCount, minScoreCount]
    }
    
  • + 0 comments

    En python

    def breakingRecords(scores):
        max_count = 0
        min_count = 0
        max_score = scores[0]
        min_score = scores[0]
        for score in scores:
            if score>max_score:
                max_count+=1
                max_score = score
            if score<min_score:
                min_count+=1
                min_score = score
        return [max_count, min_count]