• + 0 comments

    Solution C#:

        public static int sockMerchant(int n, List<int> ar)
                {
                        int pairCount = 0; 
                        var sockDict = new Dictionary<int , int>();
                        foreach(var item in ar){
                                if(sockDict.ContainsKey(item)){
                                        sockDict[item] += 1;
                                }
                                else {
                                        sockDict[item] = 1;
                                }
                        }
    
                        foreach(var kvp in sockDict){
                                pairCount+= (int)kvp.Value/2;
                        }
    
                        return pairCount;
                }