Reported May 2026
Ziplinestack

Max Stack

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

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

The mistake that sinks a first attempt at Zipline's Max Stack, reported in May 2026, is treating POP_MAX like a normal stack pop. It isn't. You have to remove the topmost copy of the max from the middle of the stack, and with up to 100000 operations a linear scan will time out. This is the classic max stack problem built on a stack plus an ordered structure. Know the trick before you open the assessment. If you blank mid-OA, StealthCoder sits invisibly on your screen as a safety net and hands you a working solution while the proctor sees nothing.

The problem

Implement a max stack by processing the finite array operations from left to right. The stack starts empty.
Each operation has one of these forms:
PUSH value: push value onto the top of the stack.
POP: remove and return the top value.
PEEK: return the top value without removing it.
PEEK_MAX: return the largest value currently in the stack without removing it.
POP_MAX: remove and return the largest value. If the maximum occurs more than once, remove the occurrence closest to the top.
Return the values produced by every operation except PUSH, in command order.

Function
runMaxStack(operations: String[]) → int[]

Examples
Example 1
operations = ["PUSH 5","PUSH 1","PUSH 5","PEEK","POP_MAX","PEEK","PEEK_MAX","POP","PEEK"]
return = [5,5,1,5,1,5]
POP_MAX removes the upper copy of 5. The stack is then [5,1] from bottom to top.
Example 2
operations = ["PUSH 2","PUSH 2","PUSH 1","POP_MAX","PEEK","POP","PEEK_MAX"]
return = [2,1,1,2]
The topmost maximum is the second pushed 2, even though 1 is above it. Removing that node leaves 1 on top.

Constraints
1 <= operations.length <= 100000.
Every operation is exactly one documented command; PUSH has one separating space before its value.
-10^9 <= value <= 10^9.
Every POP, PEEK, PEEK_MAX, and POP_MAX is issued while the stack is nonempty.
At least one operation produces output.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: don't store plain values, store nodes. Keep a doubly linked list for stack order, with PUSH appending at the tail and POP removing the tail. Pair it with a structure ordered by (value, insertion id), like a sorted map, a TreeMap, or a max-heap with lazy deletion. PEEK_MAX reads the largest key. POP_MAX takes the largest value with the highest id, which is the copy closest to the top, then unlinks that node from the list in O(1). The pitfall is the duplicate case from Example 2: the topmost 2 is below the 1, so ties must break by recency, not by position from the bottom. With a heap, mark removed ids as dead and skip them when they surface. Also handle that POP must delete from the ordered structure too. If this design stalls on you during the live OA, StealthCoder is the hedge that gets you unstuck fast.

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 Max 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 max stack. If you have time before the OA, drill that.

⏵ The honest play

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

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

Max Stack FAQ

How hard is the Zipline Max Stack problem really?+

Medium to medium-hard. PUSH, POP, PEEK and PEEK_MAX are easy. POP_MAX is the part that matters because it deletes from the middle and must pick the topmost duplicate. With 100000 operations you need roughly O(log n) per operation, not a scan.

What's the trick to POP_MAX?+

Give every pushed element a unique increasing id. Order maxima by (value, id) so the highest id among equal values wins, which is the one closest to the top. Then remove that node from a doubly linked list so stack order stays correct.

Can I use a heap instead of a sorted map?+

Yes. Push (value, id) into a max-heap and keep a set of removed ids. On PEEK_MAX or POP_MAX, pop dead entries off the top first. On POP, mark the popped id as removed. Lazy deletion keeps it amortized O(log n) per operation.

Why does the two-stack max trick fail here?+

The classic approach with a parallel max stack only supports popping from the top. POP_MAX removes an element from the middle, which breaks the parallel stack invariant. You need real deletion by node, not just a running max.

How do I prepare in 48 hours?+

Write the linked list plus sorted map version once from scratch. Then test both examples, especially the duplicate 2 case where a 1 sits on top. Practice parsing the string commands, since PUSH has a value after one space. Confirm that output skips PUSH.

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

OA at Zipline?
Invisible during screen share
Get it