Frequency Tracker
medium · 30.9% accepted · 345 likes · top 8%
Description
Design a data structure that keeps track of the values in it and answers some queries regarding their frequencies.
Implement the FrequencyTracker class.
- FrequencyTracker(): Initializes the FrequencyTracker object with an empty array initially.
- void add(int number): Adds number to the data structure.
- void deleteOne(int number): Deletes one occurrence of number from the data structure. The data structure may not contain number, and in this case nothing is deleted.
- bool hasFrequency(int frequency): Returns true if there is a number in the data structure that occurs frequency number of times, otherwise, it returns false.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Example 6:
Solution