Sales by Match

  • + 0 comments

    Python 3 solution:

    def sockMerchant(n: int, ar: list[int]) -> int:
        # return sum(v // 2 for v in collections.Counter(ar).values())
        unpaired, pairs = set(), 0
        for sock in ar:
            if sock in unpaired:
                pairs += 1
                unpaired -= {sock}
                continue
            unpaired |= {sock}
        return pairs