• + 0 comments

    Easily Understandable Approach

    public static int sockMerchant(int n, List<Integer> ar) {
        // Write your code here
        
        Set<Integer> set = new HashSet<>();
        int c=0;
    
        for(Integer i:ar){
            if(set.contains(i)){
                set.remove(i);
                c++;
            }
            else{
                set.add(i);
            }
        }
    
        return c;
        }