You are viewing a single comment's thread. Return to all comments →
public static int migratoryBirds(List<Integer> arr) { Comparator<Long> longComp = Long::compare; Map<Integer, Long> countMap = arr.stream().collect(Collectors.groupingBy((Integer i)->i, Collectors.counting())); long maxFrequency = countMap.entrySet().stream().sorted(Map.Entry.comparingByValue(longComp.reversed())). findFirst().get().getValue(); Integer key = countMap.entrySet().stream().filter(en -> en.getValue() == maxFrequency).sorted(Map.Entry.comparingByKey()).findFirst().get().getKey(); return key; }
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 →