Reported November 2025
Bloombergdesign

LRU Cache Operations

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

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

The constraint that kills the lazy answer here is 2 * 10^5 operations against a capacity up to 10^5. Bloomberg reported this LRU Cache Operations OA in November 2025, and it's the classic LRU design problem wrapped in a batch function. If you scan a list to find or evict a key, you're doing O(n) per call and the big tests will time out. The target is O(1) per get and put. If you know the hash map plus doubly linked list combo, it's a 20 minute job. If you blank on the pointer wiring, StealthCoder is the safety net running invisibly 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 two structures working together. A hash map goes from key to a node, and a doubly linked list keeps recency order, with the head side most recent and the tail side least recent. Get looks up the node, moves it to the front, and returns the value. Put updates and moves the node if the key exists, otherwise it inserts at the front and evicts the tail node if size exceeds capacity. Remember to delete the evicted key from the map too. The common pitfall is forgetting that put on an existing key must not evict anything, as Example 2 shows. Another is skipping sentinel head and tail nodes, which makes pointer edge cases messy. Only get results go in the output array. If the linked list wiring falls apart under time pressure, StealthCoder can hand you a clean implementation during the live OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

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 Bloomberg's OA.

Bloomberg reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

LRU Cache Operations FAQ

How hard is the Bloomberg LRU Cache Operations OA really?+

It's medium difficulty, but it's a well-known design problem. If you've seen the hash map plus doubly linked list approach, it's mostly careful pointer work. The batch wrapper with operations and arguments arrays adds parsing, not difficulty.

What's the trick to getting O(1) per operation?+

Pair a hash map with a doubly linked list. The map finds a node in O(1), and the list lets you move it to the front or remove the tail in O(1). A plain array or single linked list forces O(n) scans and fails the 2 * 10^5 operation limit.

Can I use a built-in ordered map instead?+

In many languages, yes. Python's OrderedDict with move_to_end, or JavaScript's Map with delete and re-insert, gives you recency order cheaply. Still, know the manual version in case the assessment restricts it or you need to explain your approach.

What edge cases break most solutions?+

Updating an existing key must refresh recency without evicting. Capacity 1 is a good test. Evicting from the list but forgetting to delete from the map is another bug. Also, only get operations append to the result array, put adds nothing.

How do I prepare for this in 48 hours?+

Write the LRU cache from scratch twice, with dummy head and tail nodes. Then test both examples by hand, including the capacity 1 case. Practice the helper functions remove and addToFront, since every operation reduces to those two.

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

OA at Bloomberg?
Invisible during screen share
Get it