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.
publicstaticintmigratoryBirds(List<Integer>arr){// Write your code hereintcurMax=0;HashMap<Integer,Integer>map=newHashMap<>();for(intnum:arr){if(map.containsKey(num)){intcurFreq=map.get(num);map.put(num,curFreq+1);curMax=Math.max(curMax,map.get(num));}else{map.put(num,1);curMax=Math.max(curMax,1);}}intres=Integer.MAX_VALUE;for(intkey:map.keySet()){if(map.get(key)==curMax){res=Math.min(res,key);}}returnres;}
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 →
Java Solution
using HashMaps