← Bloomberg Interview Insights
The OOP framing was what made this interesting.
Start by clarifying requirements (capacity, thread-safety, eviction policy) and then describe an object-oriented design with separate classes for the cache, node, and eviction policy. Explain the standard O(1) implementation using a hash map and doubly linked list, and discuss trade-offs like memory overhead and concurrency.
Pro tip: Emphasize that you separate the eviction policy from the cache storage to follow the Single Responsibility Principle and allow future extensibility (e.g., LFU). Also, mention that you would use a sentinel head/tail to simplify edge cases in the linked list.
Ask about expected capacity, thread-safety needs, and whether the cache should be generic. Confirm the eviction policy (LRU) and any performance constraints.
Identify main objects: Cache, Node (key-value pair with prev/next pointers), and EvictionPolicy interface. Explain how they interact.
Use a hash map for O(1) lookup and a doubly linked list for O(1) eviction and update. Describe how get and put operations manipulate both structures.
Discuss handling of null keys/values, capacity zero, and thread-safety (e.g., using locks or ConcurrentHashMap). Mention potential race conditions.
Compare with alternative implementations (e.g., LinkedHashMap) and discuss time/space complexity. Explain how the design supports other policies.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.