Sales by Match

  • + 0 comments

    Solution in python with O(n):

    def sockMerchant(n, ar):
        # Write your code here
        count = {}
        no_of_pair = 0
        for i in ar:
            if i not in count:
                count[i] = 1
                continue
            count[i] += 1
        for key in count:
            if count[key] >= 2:
                no_of_pair += int(count[key]/2)
    
    print(count)
    print(no_of_pair)
    return int(no_of_pair)