Reported September 2026
Physical Intelligencedesign

LRU Cache Operations

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

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

The mistake that sinks a first attempt at this Physical Intelligence OA, reported in September 2026, is forgetting that put on an existing key also counts as a use. The task is a classic LRU cache wrapped in a batch runner: feed in parallel arrays of operations and arguments, collect the get results. It's a design problem with O(1) expectations and up to 2 * 10^5 operations. If you've written this before, it's ten minutes. If you haven't, it's easy to blank on the linked list plumbing. StealthCoder is the safety net if that happens during the live OA.

The problem

Process a sequence of operations on a least recently used (LRU) cache with a fixed positive capacity.
The cache starts empty. The parallel arrays operations and arguments describe the calls in order:
get has arguments [key]. Return the stored value, or -1 when the key is absent. A successful get makes that key the most recently used.
put has arguments [key, value]. Insert or update the key and make it the most recently used. If inserting a new key would exceed capacity, first evict the least recently used key.
Return an array containing the results of the get operations, in operation order. A put operation produces no result.

Function
runLruCache(capacity: int, operations: String[], arguments: int[][]) → int[]

Examples
Example 1
capacity = 2
operations = ["put","put","get","put","get","get"]
arguments = [[1,1],[2,2],[1],[3,3],[2],[3]]
return = [1,-1,3]
Reading key 1 makes it most recent. Inserting key 3 then evicts key 2, so the final two reads return -1 and 3.
Example 2
capacity = 1
operations = ["put","put","get","put","get"]
arguments = [[5,10],[5,20],[5],[6,30],[5]]
return = [20,-1]
Updating key 5 changes its value without increasing the cache size. Inserting key 6 later evicts key 5 because the capacity is 1.

Constraints
1 <= capacity <= 10^5
1 <= operations.length <= 2 * 10^5
operations.length == arguments.length
Each operation is exactly get or put.
A get row contains exactly one integer, and a put row contains exactly two integers.
0 <= key <= 10^9
0 <= value <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a hash map from key to node plus a doubly linked list ordered by recency. Map gives O(1) lookup, the list gives O(1) move-to-front and O(1) eviction from the tail. Use dummy head and tail nodes so you never special-case empty or single-element lists. The common pitfall is the update path. Example 2 shows it: put on key 5 with capacity 1 must change the value and refresh recency, not evict anything. Another trap is evicting before checking whether the key already exists, which kills a valid entry. Also remember a failed get returns -1 and changes nothing. Loop through operations, push only get results into the output array, and skip output for put. In a pinch, a language ordered map can replace the manual list. If the pointer logic slips under pressure, StealthCoder can hand you a clean implementation during the live OA.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill LRU Cache Operations 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as lru cache. If you have time before the OA, drill that.

⏵ The honest play

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

Physical Intelligence reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

LRU Cache Operations FAQ

What's the trick to the LRU Cache Operations problem?+

Pair a hash map with a doubly linked list. The map finds a node by key in O(1). The list keeps recency order, so moving a node to the front and evicting the tail are both O(1). Dummy head and tail nodes remove most edge cases.

What's the most common mistake on this question?+

Mishandling put on an existing key. It must update the value, move the key to most recent, and not evict anything. Evicting first, before checking existence, breaks Example 2 where capacity is 1 and key 5 is updated.

Can I use a built-in ordered map instead of writing a linked list?+

Usually yes, if your language has one that supports move-to-end and pop-oldest in O(1), like an ordered dictionary. It's shorter and less bug-prone. Know the manual version too, in case the assessment restricts library use or you want to show the mechanics.

How do I prepare for this in 48 hours?+

Write the hash map plus doubly linked list version from scratch twice, without peeking. Then wrap it in the runner: loop over operations, call get or put, and collect only get results. Test both examples, especially the capacity 1 update case.

Is the design pattern still asked at Physical Intelligence?+

This one was reported in September 2026, so yes, it's current. Cache and data structure design questions are a reliable format. Expect the batch-operations wrapper rather than a class interface, and watch the 2 * 10^5 operation limit that rules out O(n) per operation.

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

OA at Physical Intelligence?
Invisible during screen share
Get it