Track Trending Emoji With Constant-Time Increment and Max Lookup
Last updated: November 29, 2026
Quick Overview
Design a counter for emoji usage in the keyboard with inc(e), dec(e), get_max() and get_min(), all in O(1) time. get_max and get_min return any emoji with the highest or lowest positive count, and an emoji whose count reaches zero is removed.
Apple
November 29, 20260
0
0 solved
Design a counter for emoji usage in the keyboard with inc(e), dec(e), get_max() and get_min(), all in O(1) time. get_max and get_min return any emoji with the highest or lowest positive count, and an emoji whose count reaches zero is removed.
The emoji keyboard surfaces frequently used emoji, so Apple interviewers frame this classic all-O(1) design question around it. They check a doubly linked list of count buckets and careful pointer updates when buckets become empty.
What the Interviewer Expects
- Explain why a heap gives O(log n) and does not meet the bar
- Maintain a doubly linked list of buckets sorted by count
- Map each emoji to its bucket
- Move an emoji to the adjacent bucket, creating or deleting buckets as needed
- Use sentinel head and tail nodes to simplify edge cases
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Show the top 5 emoji instead of just the max.
- Decay counts over time so old favorites fade.
- Persist the structure across app launches cheaply.
- Make it thread safe for the keyboard extension and the host app.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
inc(e) adds 1 (inserting at count 1). dec(e) subtracts 1 and removes the emoji at 0; decrementing a missing emoji does nothing. get_max() and get_min() return an emoji or an empty string when ...
High-Level Design
Buckets are nodes in a doubly linked list in increasing count order, each holding a count and a set of emoji. A dict maps emoji to bucket. On inc, the emoji moves from bucket c to the next bucket if...