• + 0 comments

    public static int sockMerchant(int n, List ar) { int pairCount = 0; Dictionary DictionaryObj = new Dictionary();

        foreach (var item in ar)
        {
            if (DictionaryObj.ContainsKey(item))
            {
                DictionaryObj[item]++;
            }
            else
            {
                DictionaryObj[item] = 1;
            }
        }
    
        foreach (int count in DictionaryObj.Values)
        {
            pairCount += count / 2;
        }
        return pairCount;
    }****