Breaking the Records

  • + 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;
            
        }