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

Sort 888 Discussions, By:

votes

Please Login in order to post a comment

  • melarisong
    6 years ago+ 31 comments
    import collections
    
    numShoes = int(raw_input())
    shoes = collections.Counter(map(int, raw_input().split()))
    numCust = int(raw_input())
    
    income = 0
    
    for i in range(numCust):
        size, price = map(int, raw_input().split())
        if shoes[size]: 
            income += price
            shoes[size] -= 1
    
    print income
    
    158|
    Permalink
    View more Comments..
  • chizhkovaMV
    5 years ago+ 3 comments

    without counters... coz i think there is no need to use it here

    n = input()
    boots = map(int, raw_input().split())
    orders = [map(int, raw_input().split()) for _ in range(input())]
    result = 0
    for i in orders:
        if i[0] in boots:
            result += i[1]
            boots.remove(i[0])
    print result
    
    27|
    Permalink
  • js001
    6 years ago+ 6 comments
    from collections import Counter
    n = int(input())
    s = Counter(map(int,input().split()))
    x = int(input())
    total = []
    for i in range(x):
        a,b = map(int,input().split())
        if s[a] > 0:
    		total.append(b)
    		s.subtract(Counter([a]))
        else:
            pass
    
    print (sum(total))
    
    17|
    Permalink
    View more 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
    View more Comments..
  • HMoroliya
    1 year ago+ 4 comments

    Samajh me aaye to "Copy That" XD

    from collections import Counter
    
    if __name__ == '__main__':
        total_joote, joote_ki_variety, total_grahak = (input(), Counter(map(int, input().split())), int(input()))
        galle_me_kitne_pese=0
        
        # Noto ki Barish 
        for _ in range(total_grahak):
            joota_ek_number_bada_dikhao, noto_ki_to_barish_ho_rai_hai = map(int, input().split())
            if joote_ki_variety[joota_ek_number_bada_dikhao] :
                galle_me_kitne_pese+=noto_ki_to_barish_ho_rai_hai
                joote_ki_variety[joota_ek_number_bada_dikhao]-=1
                
        # Aaj Ki Kamai
        print(galle_me_kitne_pese)
    
    7|
    Permalink
    View more Comments..
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature