← Bloomberg Interview Insights
This one had a lot of moving parts and I underestimated the resize case early on.
Start by clarifying requirements and constraints, then propose a design using a hash map for O(1) lookups and a doubly linked list for O(1) eviction ordering, with a running total of bytes. Explain how each operation maintains the byte budget and handles edge cases like oversized entries and resizing, then outline unit tests for the specified scenarios.
Pro tip: Emphasize that the byte budget changes the eviction logic: you must evict until the total size fits, and a single entry larger than capacity must be rejected outright. Also, mention that resizing may trigger multiple evictions and that you should update the total size atomically to avoid inconsistencies.
Confirm that capacity is a byte budget, entries have variable sizes, and operations must be O(1) amortized. Ask about concurrency, persistence, and whether resizing can increase or decrease capacity.
Propose a hash map (key -> node) for O(1) access and a doubly linked list to track recency (most recently used at head). Maintain a running total of bytes used.
For get: move node to head. For set: if key exists, update size and adjust total, then move to head; if new, reject if size > capacity, else insert at head and evict from tail until total <= capacity. For delete: remove node and update total. For resize: update capacity and evict from tail until total <= new capacity.
Discuss oversized entries, zero-size entries, resizing to smaller than current total, and deleting non-existent keys. Confirm O(1) amortized for all operations except resize which may evict multiple items.
List tests for size-changing updates (e.g., updating an entry to a larger size triggers evictions), eviction ordering (LRU order maintained), edge deletions (delete head, tail, only item), and capacity reduction (resize triggers evictions).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.