We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Python
  3. Collections
  4. collections.Counter()
  5. Discussions

collections.Counter()

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • willwardlow
    5 months ago+ 0 comments
    from collections import Counter
    
    x = int(input().strip())
    shoes = list(map(int, input().split()))
    shoe_counter = Counter(shoes)
    N = int(input().strip())
    
    revenue = 0
    
    for i in range(N):
        size, price = map(int, input().split())
        if shoe_counter[size] > 0:
            revenue+=price
            shoe_counter[size] -= 1
        elif shoe_counter[size] == 0:
            del shoe_counter[size]
            revenue +=0
    
    print(revenue)
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy