Reported June 2025
Kalshistack

Maximum Frequency Stack

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

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

The Kalshi OA reported in June 2025 hands you a Maximum Frequency Stack, and the whole question hinges on one data structure choice: a map of frequency to stack. If you've got an invite for the next day or two, this is the one to recognize on sight. You process push and pop operations, and each pop returns the value with the highest current frequency, breaking ties by most recent push. It looks like a heap problem and it isn't. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea below is short enough to own.

The problem

Process operations on a frequency stack.
push adds its value.
pop removes and returns a value with the greatest current frequency. Among tied values, remove the one pushed most recently.
The value paired with a pop is ignored. Return the popped values in operation order.

Function
processFrequencyStack(operations: String[], values: int[]) → int[]

Examples
Example 1
operations = ["push","push","push","push","push","push","pop","pop","pop","pop"]
values = [5,7,5,7,4,5,0,0,0,0]
return = [5,7,5,4]
The first pop chooses frequency 3; later ties use push recency.
Example 2
operations = ["push","push","pop","pop"]
values = [1,2,0,0]
return = [2,1]
Both values initially have frequency one, so 2 leaves first.
Example 3
operations = ["push","push","push","pop"]
values = [9,9,3,0]
return = [9]
Frequency two beats the more recent frequency-one value.

Constraints
1 <= operations.length == values.length <= 20000.
Each operation is push or pop.
0 <= values[i] <= 10^9 for pushes.
Every pop occurs while the structure is nonempty.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two hash maps. Keep freq[value] for the current count of each value, and group[f], a stack of values that reached frequency f, in push order. Track maxFreq. On push, increment freq[v], update maxFreq, and append v to group[freq[v]]. On pop, take the top of group[maxFreq], remove it, decrement freq[v], and if group[maxFreq] is now empty, decrement maxFreq. Every operation is O(1), so 20000 operations is trivial. The common pitfall is reaching for a heap with a timestamp, which works but costs O(log n) and needs lazy deletion bugs. Another miss is decrementing freq but leaving the value in the lower group. That's correct, because it was already pushed there earlier. Ignore the values entry on pops. If you freeze during the live OA, StealthCoder can surface this structure so you're not rebuilding it under pressure.

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 Maximum Frequency Stack 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 maximum frequency stack. If you have time before the OA, drill that.

⏵ The honest play

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

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

Maximum Frequency Stack FAQ

What's the trick to the Kalshi frequency stack problem?+

Use a map from value to count, and a map from frequency to a stack of values. Each push adds the value to the stack for its new frequency. Each pop takes from the stack at the max frequency. Recency tie-breaking comes free from stack order.

How hard is this problem really?+

Medium-hard if you've never seen it, easy once you know the frequency-bucket idea. The code is under 25 lines. The difficulty is seeing that you don't need a heap, since a stack per frequency handles ties automatically.

Why not just use a priority queue?+

You can, with entries of frequency and push index. But stale entries pile up as counts change, and you pay O(log n) per operation. The bucket approach is cleaner, faster, and has fewer edge cases to get wrong under pressure.

How do I handle the values array on pop operations?+

Ignore it. The statement says the value paired with a pop is ignored, so the zeros in the examples mean nothing. Just branch on the operation string and only read values[i] when it's a push. Append popped results to the output list in order.

How do I prepare for this in 48 hours?+

Write the two-map solution from scratch twice, then trace Example 1 by hand to confirm the output is [5,7,5,4]. Also test the case where maxFreq must drop after a pop empties its bucket. That's the bug most people hit.

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

OA at Kalshi?
Invisible during screen share
Get it