Practice All O`one Data Structure
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
AllOne starts empty. inc(key) raises its count by one, inserting an absent key at one. dec(key) lowers an existing key's count, removing it at zero. getMaxKey() and getMinKey() return any key at the respective extreme, or an empty string when no keys remain. Each operation must run in average O(1) time. Practice approach: Link nonempty count buckets in increasing order and map each key to its bucket. Increment and decrement move a key only to an adjacent count bucket, creating or deleting buckets as needed. The endpoint buckets provide extrema. Test a final deletion, ties, and moving a key into an existing bucket.
Source: All O`one Data Structure on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["AllOne","getMinKey","inc","inc","inc","getMaxKey","getMinKey","dec","dec","getMinKey"] [[],[],["a"],["a"],["b"],[],[],["b"],["a"],[]]
[null,"",null,null,null,"a","b",null,null,"a"]
Counts reach a:2 and b:1. Removing b and decrementing a leaves only a, so it is both the minimum and maximum key.
Constraints
Related LeetCode Problems
Practice more problems similar to All O`one Data Structure.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.