 All Problems
All O`one Data Structure
hard
design
hash table
linked list
amazon
google

Design a data structure to store strings and their counts, with the following operations all in O(1):

  • inc(String key) — insert with count 1 or increment count by 1.
  • dec(String key) — decrement count. Remove if count reaches 0.
  • getMaxKey() — return one key with the maximum count, or "".
  • getMinKey() — return one key with the minimum count, or "".

Example:

inc("a"), inc("b"), inc("b"), inc("c"), inc("c"), inc("c")
getMaxKey()→"c", getMinKey()→"a"
Run to check your code against the sample cases, or submit to run every case