← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Oracle SWE interview that came down to a classic LRU cache problem with a follow-up that actually had some teeth to it. Pretty standard coding round overall but the TTL extension kept things interesting.

Questions Asked (2)

Q1

Design and implement an LRU cache class with get and put operations, both running in O(1) average time.

Algorithms & Data StructuresSystem Design
Author's notes

Knew this one cold.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then propose a design using a hash map and a doubly linked list to achieve O(1) operations. Walk through the implementation details, including edge cases and potential optimizations, and discuss how you would test the solution.

Pro tip: Mention that you would use a doubly linked list to maintain the access order and a hash map for O(1) lookups, and highlight that this combination is the standard for LRU caches. Also, discuss thread-safety if the cache might be used in a concurrent environment, as Oracle often deals with high-performance systems.

1. Clarify Requirements

Ask about the expected operations, capacity, and whether thread-safety is required. Confirm that get and put must be O(1) on average.

2. Choose Data Structures

Explain that a hash map provides O(1) access to cache entries, and a doubly linked list maintains the order of usage, allowing O(1) removal and insertion.

3. Design the Algorithm

Describe how get moves the accessed item to the front (most recently used), and put adds or updates an item, evicting the least recently used item when capacity is exceeded.

4. Handle Edge Cases

Discuss handling of capacity 0 or 1, updating existing keys, and ensuring the eviction policy works correctly when the cache is full.

5. Implement and Test

Write clean code with helper functions for adding/removing nodes, and outline test cases including basic operations, eviction, and concurrency if applicable.

Key Points to Mention

  • Hash map for O(1) key lookup
  • Doubly linked list for O(1) insertion and deletion
  • Maintaining most recently used (MRU) at the head and least recently used (LRU) at the tail
  • Eviction policy when capacity is reached
  • Thread-safety considerations (e.g., using locks or concurrent data structures)
  • Time and space complexity analysis

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

Q2

How would you extend the LRU cache to support per-entry expiration (TTL)? Walk through the tradeoffs between different approaches.

System DesignTechnical Trade-offsAlgorithms & Data Structures
Author's notes

This is where I got a little tripped up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: TTL semantics, eviction policy, and concurrency needs. Then present a baseline approach (e.g., lazy expiration with a min-heap) and compare it to alternatives like timing wheels or hierarchical caches, discussing trade-offs in time/space complexity, accuracy, and operational overhead. Conclude with a recommendation based on the use case.

Pro tip: Mention that TTL and LRU can conflict: an expired entry might still be the most recently used, so you need to decide whether expiration should trigger immediate eviction or be handled lazily. Also, highlight that in distributed systems, TTL often requires a background sweeper to avoid memory leaks.

1. Clarify Requirements

Ask about TTL semantics (per-entry, global, sliding vs. absolute), expected load, memory constraints, and whether strict expiration is required. This ensures you design for the right problem.

2. Baseline Approach: Lazy Expiration with Min-Heap

Extend the LRU cache with a min-heap keyed by expiration time. On access, check if the entry is expired; if so, evict it. Periodically or on eviction, remove expired entries from the heap. Discuss complexity: O(log n) for heap operations, but lazy checks add overhead.

3. Alternative: Timing Wheel

Use a timing wheel (hierarchical or simple) to efficiently track expiration times. This provides O(1) insertion and deletion, and periodic advancement triggers expiration. Trade-off: more complex to implement and may have coarser granularity.

4. Alternative: Background Sweeper

Run a background thread that periodically scans and evicts expired entries. This decouples expiration from access, but can cause memory spikes and requires synchronization. Trade-off: simplicity vs. potential latency and memory overhead.

5. Compare and Recommend

Summarize trade-offs: min-heap is simple but adds O(log n) overhead; timing wheel is efficient but complex; background sweeper is easy but may delay eviction. Recommend based on requirements (e.g., for high-throughput, timing wheel; for simplicity, lazy with heap).

Key Points to Mention

  • TTL semantics: absolute vs. sliding expiration, and whether expiration should be strict or best-effort.
  • Data structures: min-heap, timing wheel, or sorted set for efficient expiration tracking.
  • Concurrency: thread-safety, locking strategies, and avoiding race conditions between access and expiration.
  • Memory management: preventing leaks from expired but not evicted entries, and handling memory pressure.
  • Performance trade-offs: time complexity of operations, overhead of background threads, and impact on cache hit rate.
  • Integration with LRU: how expiration interacts with LRU eviction (e.g., expired entries should be removed first, but may not be the least recently used).

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