collections.Counter()

  • + 7 comments

    Here is Python 3 solution from my HackerrankPractice repository:

    import collections
    
    
    number_of_shoes = int(input())
    sizes_in_stock = collections.Counter(map(int, input().split()))
    
    total_revenue = 0
    
    for _ in range(int(input())):
        size, price = map(int, input().split())
        if sizes_in_stock[size]:
            total_revenue += price
            sizes_in_stock[size] -= 1
    
    print(total_revenue)
    

    Feel free to ask if you have any questions :)