These days, interviewers are increasingly testing design and implementation skills rather than just algorithmic problem-solving. If you're preparing for interviews, make sure you're comfortable with these problems!
Build a cache that evicts the least recently used item when full. You need O(1) for both get and put, which means combining a hash map with a doubly linked list.
Follow-ups:
Implement a stack that can return its minimum element in O(1) time. Simple but elegant - teaches you to maintain auxiliary information efficiently.
Follow-ups:
Build the foundation for autocomplete and spell checkers. A tree where each node represents a character, perfect for prefix-based operations.
Follow-ups:
Build a hash map from scratch without using built-in hash tables. You'll handle hash functions, collision resolution, and understand what's happening under the hood.
Follow-ups:
Support insert, delete, and get random element - all in O(1). The trick is combining an ArrayList for random access with a HashMap for O(1) lookup. The delete operation is beautifully clever.
Follow-ups:
Build a simplified Twitter with post, follow, unfollow, and timeline features. Tests your ability to model real-world systems and efficiently merge sorted lists from multiple users.
A stack where you can increment the bottom k elements. Naive approach is O(k), but lazy propagation makes it O(1). Great introduction to deferred operations.
Follow-ups:
Store versioned values with timestamps and retrieve the value at or before any timestamp. Teaches you about versioning systems and binary search on historical data.
Follow-ups:
Implement a queue with fixed size using an array. The wraparound logic and distinguishing between full and empty states is trickier than it looks.
Follow-ups:
Support set, snap, and get operations where snap creates a version checkpoint. The key is not copying the entire array - only store what changed in each snapshot.
Add few more best problems in the comments below !!
Good luck with your interviews! 🚀