• + 0 comments

    Java Solution

    using HashMaps

     public static int migratoryBirds(List<Integer> arr) {
        // Write your code here
            int curMax = 0 ;
            HashMap<Integer , Integer> map = new HashMap<>();
            for(int num : arr){
                if(map.containsKey(num)){
                    int curFreq = 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);
                }
            }
            int res = Integer.MAX_VALUE;
            for(int key : map.keySet()){
                if(map.get(key) == curMax){
                    res = Math.min(res,key);
                }
            }
            return res;
        }