• + 0 comments

    Python

    def count_elements(n, arr):
        pairs = 0
        count = 0
        for x in arr:
            if n == x:
                count += 1
            if count == 2:
                pairs += 1
                count = 0
        return pairs
    
    def sockMerchant(n, ar):
        count = 0
        numbers = set()
        [numbers.add(x) for x in ar]
        for x in numbers:
            count += count_elements(x, ar)
        return count