Sales by Match

  • + 0 comments

    ` //// Python, using dict and flags:

    def sockMerchant(n, ar): no_pairs : int = 0 pair_nopair : dict[int, bool] = {}

    for sock in ar:
        if sock not in pair_nopair:
            pair_nopair[sock] = True
            continue
        if pair_nopair[sock]:
            no_pairs = no_pairs + 1
        pair_nopair[sock] = not pair_nopair[sock]
    
    return no_pairs
    

    `