• + 0 comments
     public static int sockMerchant(int n, List<Integer> ar) {
        // Write your code here
            Map<Integer,Integer> colorCount =new HashMap<>();
            for(int sock : ar ){
                colorCount.put(sock, colorCount.getOrDefault(sock,0)+1);
            }
            
            Integer pairs = 0;
            for(Integer c : colorCount.values()){
                pairs+=c/2;
                
    
            }
            return pairs;
    
        }
    
    }