← Atlassian Interview InsightsSoftware Engineer
My first instinct was a heap and a hashmap, which is wrong the moment you think about dec() and removal.
Start by clarifying the requirements and constraints, then propose a design using a hash map for O(1) key lookup and a doubly linked list of buckets to group keys by count, enabling O(1) access to min and max. Walk through each operation, explaining how you maintain the bucket list sorted by count and handle key removal when count reaches zero.
Pro tip: Emphasize that the bucket list is sorted by count, so getMaxKey and getMinKey are O(1) by checking the tail and head respectively; this shows you understand the invariant that makes the design work.
Confirm that keys are strings, counts are integers, and operations should be O(1) average. Ask about concurrency or memory constraints if relevant.
Use a hash map from key to its bucket, and a doubly linked list of buckets where each bucket holds a set of keys with the same count. Buckets are ordered by count.
For inc, move the key to the next bucket (or create one) and update the hash map; for dec, move to the previous bucket, and if count becomes zero, remove the key entirely.
Return any key from the last bucket for max and from the first bucket for min, both in O(1) by accessing the head or tail of the bucket list.
Cover empty structure, single key, and bucket merging/removal. Confirm all operations are O(1) average and mention space complexity O(n).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.