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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • 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 →

  • marinskiy
    4 years ago+ 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 :)

    16|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature