You are viewing a single comment's thread. Return to all comments →
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; }
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
Simple solution