Practice Frequency Tracker
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
FrequencyTracker starts empty. add(number) inserts one occurrence. deleteOne(number) removes one occurrence if present and otherwise changes nothing. hasFrequency(frequency) reports whether any stored number has exactly that positive frequency. Practice approach: Maintain both number counts and a histogram of how many numbers have each positive count. Move a number between histogram buckets on insertion or deletion. Do not create a zero-frequency entry for absent numbers. All operations can be expected O(1). Test deleting an absent value and removing the last member of a frequency bucket.
Source: Frequency Tracker on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["FrequencyTracker","add","add","hasFrequency","deleteOne","hasFrequency","hasFrequency","deleteOne","hasFrequency"] [[],[4],[4],[2],[4],[2],[1],[4],[1]]
[null,null,null,true,null,false,true,null,false]
The count of 4 moves from two to one to zero; empty frequency buckets must stop matching.
Constraints
Related LeetCode Problems
Practice more problems similar to Frequency Tracker.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.