We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classResult{/* * Complete the 'migratoryBirds' function below. * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY arr as parameter. */staticLongmaxSighting=0L;publicstaticintmigratoryBirds(List<Integer>arr){Map<Integer,Long>sightingCount=arr.stream().collect(Collectors.groupingBy(Function.identity(),Collectors.counting()));for(Map.Entry<Integer,Long>entry:sightingCount.entrySet()){if(entry.getValue()>maxSighting){maxSighting=entry.getValue();}}returnsightingCount.entrySet().stream().filter(e->e.getValue()==maxSighting).sorted(Map.Entry.comparingByKey()).map(e->e.getKey()).findFirst().get();}}
Cookie support is required to access HackerRank
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 →