• + 9 comments

    Hashset storing values by placing values into an array by an index calculated according to GetHashCode of the value.

    Actually I had the same idea but simpler:

    		int[] pairsToSell = new int[n];
            int countToSell = 0;
            foreach(int sock in socks) {
                var ind = sock % n;
                pairsToSell[ind] +=1;
                if (pairsToSell[ind] == 2) {
                    countToSell++;
                    pairsToSell[ind] = 0;
                }
            }
            
            Console.WriteLine(countToSell);
    

    Since sock color is a positive integer number, there is no need to take hash code of it. Instead I just used sock%n to recognize appropriate index.