• + 0 comments

    Simple solution

        public static int migratoryBirds(List<Integer> arr) {
            int[] freq = new int[5];
            int n = arr.size();
            int max = 0;
    
            for (int i: arr) {
                freq[i - 1]++;
                if (freq[i - 1] > max)
                max = freq[i - 1];
            }
            
            for (int i = 0; i < 5; i++) {
                if (freq[i] == max)
                return i + 1;
            }
            
            return -1;
        }