prepbook
  • Introduction
  • Some common stuff
    • python __repr__
    • HackerRank input tips
  • Data Structures and Algorithms
    • Breadth first search
    • Depth First Search
    • Dijkstra
    • A* Search Algorithm
    • Binary Search
    • python counter
    • Sorting
      • Merge Sort
      • Quick Sort
    • Priority Queue
  • Multiprocessing vs Threading
  • Common Coding
    • Find loop in lin list
    • Maximum sum subarray
  • Coding
    • Valid palindrome
    • Palindrome number
    • Remove duplicates from sorted array
    • Island perimeter
    • Serialize and Deserialize Binary Tree
    • Valid Soduku
    • Word Pattern
    • Word Pattern II
    • Group Anagrams
    • Implement Trie
    • Deep copy list with random node
    • Palindrome Permutation
    • Combination Sum
    • Clone Graph
    • Generate parenthesis
    • Fibonacci Number
    • LRU Cache
    • Merge two sorted arrays in place
    • Hamming Distance
    • Merge K sorted arrays
    • Kth smalles element in BST
    • Kth largest element in an array
    • Remove duplicates from sorted list
    • Power of 2
    • Nested list weight sum
    • SIngle number in a list
    • Factor combinations
    • Delete node from BST
  • hacker Rank
    • Coding
      • print staircase
      • Drawing book
      • Challenge 0
      • Min-Max sum
  • WorkRelatedCoding
    • Rectangle Overlap
  • Python tips
Powered by GitBook
On this page

Was this helpful?

  1. Data Structures and Algorithms

python counter

Task

Raghu is a shoe shop owner. His shop has number of shoes. He has a list containing the size of each shoe he has in his shop. There are number of customers who are willing to pay amount of money only if they get the shoe of their desired size.

Your task is to compute how much money earned.

Input Format

The first line contains, the number of shoes. The second line contains the space separated list of all the shoe sizes in the shop. The third line contains, the number of customers. The next lines contain the space separated values of the desired by the customer and, the price of the shoe.

Sample Input

10
2 3 4 5 6 8 7 6 5 18
6
6 55
6 45
6 55
4 40
18 60
10 50
# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import Counter
X = int(raw_input().strip())
shoeSizeList = map(int,raw_input().strip().split(' '))
Cntr = Counter(shoeSizeList)

N = int(raw_input().strip())
#print 'list: ', shoeSizeList, type(shoeSizeList)

earnings = 0
for a0 in xrange(N):
    shoeSize,price = map(int, raw_input().strip().split(' '))
    if shoeSize in Cntr and Cntr[shoeSize] > 0:
        earnings += price
        Cntr[shoeSize] -= 1
        #print 'earnings: ', earnings

print earnings
PreviousBinary SearchNextSorting

Last updated 5 years ago

Was this helpful?