Reported September 2026
Salesforcedesign

LFU Cache

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

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

Salesforce reportedly served this one in September 2026, and it's LFU Cache wearing a string-parsing costume. Strip the command format and you're building the classic least-frequently-used cache with O(1) get and put. If the OA lands in your inbox, expect to spend most of your time on bookkeeping, not cleverness. The design is two hash maps plus a doubly linked list per frequency, and one pointer for the minimum frequency. If you blank on the structure mid-assessment, StealthCoder is the invisible safety net that reads the problem and hands you a working layout.

The problem

Process commands on an initially empty least-frequently-used cache with positive integer capacity.
put key value inserts a new key or updates an existing key.
get key returns the stored value, or -1 when the key is absent.
For this exercise, assume a successful get and a put that updates an existing key each increase that key's frequency by one and make it most recently used within its new frequency. A new key starts with frequency one.
When a new insertion would exceed capacity, evict the key with the smallest frequency. Break a frequency tie by evicting the least recently used key. Return the results of all get commands in order. Each operation should run in average O(1) time.

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

Examples
Example 1
capacity = 2
operations = ["put 1 1","put 2 2","get 1","put 3 3","get 2","get 3","put 4 4","get 1","get 3","get 4"]
return = [1,-1,3,-1,3,4]
Reading key 1 raises its frequency, so key 2 is evicted first. Later keys 1 and 3 tie on frequency, and key 1 is least recent.
Example 2
capacity = 1
operations = ["put 7 5","put 7 8","get 7","put 9 4","get 7","get 9"]
return = [8,-1,4]
Updating key 7 changes its value and frequency. Inserting key 9 into a one-entry cache then evicts key 7.

Constraints
1 <= capacity <= 3000.
1 <= operations.length <= 2 * 10^4.
Each command is exactly get key or put key value.
Keys and values fit in signed 32-bit integers.
At least one command is get.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a key map to node (value, frequency) and a frequency map to an ordered list of keys, oldest first. On every successful get or update, move the key from its frequency bucket to freq+1 and append it at the most recent end. Track minFreq. If the old bucket empties and it was minFreq, bump minFreq by one. On inserting a new key at capacity, evict the oldest key from the minFreq bucket, then insert with frequency 1 and set minFreq to 1. The common pitfalls: forgetting that put on an existing key raises frequency, forgetting to reset minFreq to 1 on insert, and evicting before checking whether the key already exists. In Python, an OrderedDict per frequency works well. Also parse each command by splitting on spaces and only collect get results. If you freeze live, StealthCoder is the hedge that gives you the full structure fast.

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 LFU 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 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 lfu cache. If you have time before the OA, drill that.

⏵ The honest play

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

Salesforce 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.

LFU Cache FAQ

How hard is this Salesforce LFU Cache question really?+

It's a hard-tier design problem, but it's well known. The logic is mechanical once you see the two maps and the minFreq pointer. The risk is off-by-one bugs in frequency bookkeeping, not the concept. Write it carefully and trace Example 1 by hand before submitting.

What's the core trick for O(1) operations?+

Keep a map from key to value and frequency, plus a map from frequency to an insertion-ordered set of keys. Track the minimum frequency. Moving a key between buckets is O(1), and eviction pops the oldest key from the minFreq bucket. No sorting or heaps needed.

When do I update minFreq?+

Two places. After a touch, if the old bucket is now empty and it equaled minFreq, increment minFreq. On inserting a brand new key, set minFreq to 1. Eviction happens before that insert, so the evicted key's bucket doesn't matter afterward.

Does put on an existing key count as a use?+

Yes, per this problem's rules. Updating an existing key changes its value, raises its frequency by one, and makes it most recently used in the new bucket. Example 2 shows this with key 7. Don't evict anything on an update, even at capacity.

How do I prepare for this in 48 hours?+

Implement it once from scratch, using OrderedDict in Python or LinkedHashSet in Java. Then test capacity 1, repeated puts on the same key, and get on a missing key. Also practice the command parsing, since the input is strings and only get results go in the output.

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

OA at Salesforce?
Invisible during screen share
Get it