• + 0 comments
    // Javascript
    function sockMerchant(n, ar) {
        let pairCount = 0;
        let i = 0;
        ar.sort((a,b) => a - b);
        while(i < n - 1){
            if(ar[i] == ar[i+1]){
                pairCount++;
                i+=2;
            }
            else {
                i++;
            }
        }
        return pairCount;
    }