Reported September 2026
Netflixdesign

Capacity-Limited Timed Cache

Reported by candidates from Netflix's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Netflix OA. Under 2s to a working solution.
Founder's read

Netflix reportedly served this one in September 2026: a capacity-limited cache where every entry has its own TTL and eviction is by oldest PUT timestamp, with ties broken by smaller key. The whole problem hinges on holding two ordered structures over the same entries: one keyed by expiration, one keyed by (age, key). You've got an OA coming and this is a design problem wearing a simulation costume. If you blank on the bookkeeping, StealthCoder is the invisible safety net on the live OA. Know the shape first and it gets much easier.

The problem

Implement a key-value cache with a fixed positive capacity. Every entry has its own expiration time, and the cache processes operations whose timestamps are nondecreasing.
Each row in operations has one of these forms:
[0, key, value, ttl, timestamp] is a PUT. It creates or replaces key with value. The entry expires at timestamp + ttl. A successful PUT sets the entry's age to this timestamp.
[1, key, timestamp] is a GET. It returns the current value for key, or -1 when the key is absent or expired. A GET does not change an entry's age.
Before processing every operation, remove all entries whose expiration time is less than or equal to the operation's timestamp. When a PUT inserts a new key and the cache still contains capacity live entries, evict the live entry with the smallest most-recent PUT timestamp. If several live entries have that same timestamp, evict the one with the smaller key. Replacing an existing live key refreshes its value, expiration time, and age without evicting another entry.
Return the results of the GET operations in encounter order. PUT operations do not add a result.

Function
runCapacityTimedCache(capacity: int, operations: int[][]) → int[]

Examples
Example 1
capacity = 2
operations = [[0,1,10,10,0],[0,2,20,10,1],[1,1,2],[0,3,30,10,3],[1,1,3],[1,2,3],[1,3,3]]
return = [10,-1,20,30]
The cache is full when key 3 is inserted at time 3. Key 1 has the oldest live PUT timestamp, so it is evicted. Keys 2 and 3 remain available.
Example 2
capacity = 2
operations = [[0,1,10,2,0],[0,2,20,10,0],[0,3,30,10,2],[1,1,2],[1,2,2],[1,3,2]]
return = [-1,20,30]
Key 1 expires exactly at time 2 and is removed before key 3 is inserted. The expired entry frees capacity, so no live key is evicted.
Example 3
capacity = 2
operations = [[0,2,20,10,0],[0,1,10,10,0],[0,3,30,10,0],[1,1,0],[1,2,0],[1,3,0]]
return = [-1,20,30]
Keys 1 and 2 have equal age when key 3 arrives. The smaller key, 1, is evicted by the tie rule.

Constraints
1 <= capacity <= 100000.
1 <= operations.length <= 200000, and at least one operation is a GET.
Every PUT row is [0, key, value, ttl, timestamp].
Every GET row is [1, key, timestamp].
0 <= key, value, timestamp <= 10^9.
1 <= ttl <= 10^9.
Operation timestamps are nondecreasing.
Expiration times fit a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep a hash map from key to (value, expiry, age). Add a min-heap on (expiry, key) and a second ordered set, or heap, on (age, key). Before each operation, pop from the expiry heap while expiry <= timestamp and delete those entries from the map and the age structure. The pitfall is stale data. A replaced key leaves old records behind, so use lazy deletion: when you pop a record, check it still matches the map's current expiry or age, otherwise skip it. Same check when evicting from the age heap. Also remember GET never changes age, so no refresh there. Replacing a live key evicts nothing. Expiry uses <=, so an entry with expiry equal to the timestamp is already dead. Total cost is O(n log n), fine for 200000 operations. StealthCoder covers you on the live OA if the lazy-deletion details slip.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Capacity-Limited Timed Cache cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Netflix's OA.

Netflix reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Capacity-Limited Timed Cache FAQ

What's the trick in the Netflix capacity-limited timed cache?+

Two heaps plus a hash map. One heap orders by expiration, the other by (age, key) for eviction. Use lazy deletion so replaced or expired entries get skipped when popped, instead of searching heaps to remove them. That keeps every operation at O(log n).

Is this just an LRU cache?+

No. LRU updates recency on GET. Here GET never changes age, and age is the latest PUT timestamp only. Eviction is oldest PUT with the smaller key as tiebreak. A linked-list LRU will give wrong answers on the GET examples.

What edge cases break most solutions?+

Expiry boundary: an entry with expiry equal to the timestamp is removed before the operation runs. Also replacing a live key must not evict anything, and an expired key reinserted counts as a new insert. Check example 2 against your code.

How hard is this really?+

Medium-hard on bookkeeping, easy on concepts. Nothing exotic is needed, just heaps and a map. Most failures come from stale heap entries and tie-breaking, not from the algorithm. Expect to spend your time on correctness rather than ideas.

How do I prepare in 48 hours?+

Write this cache once from scratch with lazy deletion, then run the three examples by hand. Practice a heap with tuple ordering in your language and a stale-entry check on pop. Test with capacity 1 and many equal timestamps.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Netflix.

OA at Netflix?
Invisible during screen share
Get it