• + 0 comments
    1. Convert list to int sorted array
    2. Create Pair counter which will count the number of paired element
    3. If pair matches then increase counter by 1,
    public static int sockMerchant(int n, List<Integer> ar) {
            // Write your code here
            
            int[] arr = ar.stream().mapToInt(x->x).sorted().toArray();
    
            int pairCounter=0;
            for(int i=0;i<arr.length-1;i++){
                if(arr[i] == arr[i+1]){
                    i=i+1;
                    pairCounter++;
                }
            }
            
            return pairCounter;
        }
    
    }