We have a collection of integers which is initially empty and events of the following types:
1. insert a new integer into the collection2. remove an integer from the collection
3. return the number of occurences of a given integer
Implement all the operations above.
Example:
Input:
insert(5)
insert(2)
insert(5)
count(5)
remove(5)
count(5)
Output:2 1
Explanation There are two 5s at the first count and one after the second
Note:
Each operation should run in O(1) time and your algorithm should use O(n) space.
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check