Design a data structure that tracks the frequency of string keys and allows for efficient updates and queries.
Implement the AllOne class with these methods:
Constructor: Initializes the data structure.
inc(String key): Increases the count of the given key by
dec(String key): Decreases the count of the given key by
getMaxKey(): Returns any one key with the highest count. If the data structure is empty, return an empty string.
getMinKey(): Returns any one key with the lowest count. If the data structure is empty, return an empty string.
Note: All operations must be performed in average
time complexity.
Constraints:
key.length
key consists only of lowercase English letters.
It is guaranteed that each call to dec is made with a key that exists in the data structure.
At most
Design a data structure that tracks the frequency of string keys and allows for efficient updates and queries.
Implement the AllOne class with these methods:
Constructor: Initializes the data structure.
inc(String key): Increases the count of the given key by
dec(String key): Decreases the count of the given key by
getMaxKey(): Returns any one key with the highest count. If the data structure is empty, return an empty string.
getMinKey(): Returns any one key with the lowest count. If the data structure is empty, return an empty string.
Note: All operations must be performed in average
time complexity.
Constraints:
key.length
key consists only of lowercase English letters.
It is guaranteed that each call to dec is made with a key that exists in the data structure.
At most