← IBM Interview Insights

IBM·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Did a technical interview at IBM for a mid-level role and got hit with a genuinely brutal data structure question. Left feeling confused about what they're actually looking for at that level.

Questions Asked (1)

Q1

Design an LRU Cache that supports TTL-based eviction, a max capacity constraint, and a method to retrieve the running global average of TTL values across all current items. Implement get(key), put(key, value), and get_average().

Algorithms & Data StructuresSystem Design
Author's notes

This wrecked me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: TTL semantics (per-item expiration), capacity eviction policy (LRU), and how get_average should behave (e.g., average of remaining TTLs or original TTLs). Then design a data structure combining a hash map for O(1) key lookup, a doubly linked list for LRU ordering, and a min-heap or time-ordered structure for TTL expiration, while maintaining running sum and count for average. Discuss trade-offs and edge cases before coding.

Pro tip: Mention that TTL eviction can be lazy (on access) or active (background thread), and that lazy eviction simplifies implementation but may leave expired items until accessed; also note that get_average should likely exclude expired items, so you need to purge them first.

1. Clarify Requirements and Assumptions

Ask about TTL semantics (absolute vs sliding), eviction policy details (LRU on get/put), and whether get_average includes expired items. Confirm expected time complexities and concurrency needs.

2. Design Core Data Structures

Use a hash map for O(1) key access, a doubly linked list for LRU order, and a min-heap or balanced BST keyed by expiration time for TTL. Maintain running sum and count of TTLs for average.

3. Define Operations and Eviction Logic

For get: check existence, TTL validity, update LRU, and return value. For put: insert/update, set TTL, evict LRU if over capacity, and remove expired items. For get_average: purge expired items then return sum/count.

4. Handle Edge Cases and Complexity

Address empty cache, expired items on get, updating TTL on put, and capacity=0. Analyze time complexity: O(1) for get/put (amortized with heap), O(log n) for TTL operations, and O(1) for average after purge.

5. Discuss Optimizations and Trade-offs

Consider using a timing wheel for efficient TTL management, lazy vs active expiration, and thread-safety. Mention that maintaining average of original TTLs vs remaining TTLs changes implementation.

Key Points to Mention

  • Combination of hash map and doubly linked list for O(1) LRU operations
  • Use of a min-heap or time-ordered structure for efficient TTL expiration
  • Running sum and count to compute average in O(1) after purging expired items
  • Lazy vs active expiration strategies and their trade-offs
  • Handling of edge cases: empty cache, expired get, capacity overflow, TTL updates
  • Time and space complexity analysis for each operation

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.