• + 0 comments

    Java

    public static int migratoryBirds(List<Integer> arr) {
            int max = Integer.MIN_VALUE;
            int count = 0;
            int idMin = Integer.MAX_VALUE;
            int id = 0;
            
            Collections.sort(arr);
            
            for (int i = 0, j = 1; j < arr.size() - 1; i++, j++) {
                if (arr.get(i) == arr.get(j + 1)) {
                    id = arr.get(i);
                    count++;
                    if (count > max) {
                        max = count;
                        idMin = id;
                    }
                } else {
                    count = 0;
                }
            }
            return idMin;
        }