You are viewing a single comment's thread. Return to all comments →
public static int migratoryBirds(List<Integer> arr) { // Write your code here Map<Integer,Integer> countMap = new HashMap<>(); List<Integer> maxList = new ArrayList<>(); for(Integer i : arr){ countMap.put(i, countMap.getOrDefault(i, 0) + 1); } Integer max = Collections.max(countMap.values()); for(Map.Entry<Integer, Integer> maps : countMap.entrySet() ){ if(maps.getValue() == max){ maxList.add(maps.getKey()); } } return Collections.min(maxList); }
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 →