Sort by

recency

|

2245 Discussions

|

  • + 0 comments
    def breakingRecords(scores):
        minScore = maxScore = scores[0]
        minCount = maxCount = 0
        for s in range(1, len(scores)):
            if scores[s] > maxScore:
                maxScore = scores[s]
                maxCount += 1
            elif scores[s] < minScore:
                minScore = scores[s]
                minCount += 1
        return [maxCount, minCount]
    
  • + 0 comments

    hello hackerrank citizens, this is my answer using python, can I upgrade the code to make it more efficient and clean?

    def breakingRecords(scores): batas_atas = scores[0] batas_bawah = scores[0] best = [] worse = []

    for score in scores:
        if (score > batas_atas):
            best.append(score)
            batas_atas = score
    
        elif (score < batas_bawah):
            worse.append(score)
            batas_bawah = score
    
    result = [len(best), len(worse)]
    
    return result;
    
  • + 0 comments

    Hi Guys! what do you think about this approach? focused on referencial transparency and immutability. I really wanted to avoid the so popular imperative way.

    C#

    public readonly record struct BreakingRecords(int maxScore, int minScore, int most, int least)
    {
        private BreakingRecords Init(int first)
            => new(first, first, 0, 0);
            
        private BreakingRecords Apply(int score)
            => 
                score > this.maxScore ? this with { most = most + 1, maxScore = score } : 
                score < this.minScore ? this with { least = least + 1, minScore = score } :
                this;    
        
        public string GetRecords(IReadOnlyList<int> scores)
        {                                                               
            var state = Init(scores[0]);
            var finalState = scores.Skip(1).Aggregate(state, (st, t) => st.Apply(t));
            return $"{finalState.most} {finalState.least}";
        }
    }
    
  • + 0 comments

    Java

    	int min = scores.get(0);
            int max = scores.get(0);
            
            int minRecord = 0;
            int maxRecord = 0;
            
            for (int i = 1; i < scores.size(); i++) {
                if (scores.get(i) < min) {
                    min = scores.get(i);
                    minRecord++;
                } else if (scores.get(i) > max) {
                    max = scores.get(i);
                    maxRecord++;
                }
                
            }
                
            return Arrays.asList(maxRecord, minRecord);
    
  • + 0 comments

    Java Solution

    public static List<Integer> breakingRecords(List<Integer> scores) {
    
        int max=scores.get(0),min=scores.get(0),minCount=0,maxCount=0;
        for(int x : scores){
            if(x>max){
                max=x;
                maxCount++;
            }
            if(x<min){
                min=x;
                minCount++;
            }
    
        }   
         List<Integer> resultList = new ArrayList<>();
            resultList.add(maxCount);
            resultList.add(minCount);   
         return resultList;
    
    }