Design a structure that stores string counts with inc(key), dec(key), getMaxKey() and getMinKey(), each in O(1) time. inc adds the key with count 1 if absent; dec removes it when its count reaches 0. getMaxKey and getMinKey return any key with the highest or lowest count, or "" if empty.
Practise this challenge
All coding challenges