Min Stack
Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The ZipRecruiter Min Stack OA, reported in February 2017, punishes one mistake on the first attempt: tracking a single running minimum and forgetting what happens when that value gets popped. You're handed a stream of strings like "push -2" and "getMin", and you return outputs for everything except push. It's a classic stack problem with a parsing layer on top. The logic is short, but it's easy to botch under a timer. If you blank in the live assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the clean version.
The problem
For this practice version, exercise the stack through the operation stream below. Process operations on a stack that can return its current minimum in constant time. push x pushes integer x and produces no output. pop removes and returns the top value. top returns the top value without removing it. getMin returns the smallest value currently in the stack. Return the outputs of every operation except push, in encounter order. Function processMinStack(operations: String[]) → int[] Examples Example 1 operations = ["push -2","push 0","push -3","getMin","pop","top","getMin"] return = [-3,-3,0,-2] The minimum becomes -3. Popping returns -3, exposing top 0 and minimum -2. Example 2 operations = ["push 2","push 2","getMin","pop","getMin"] return = [2,2,2] Duplicate minima are tracked independently, so one pop leaves the same minimum. Constraints 1 <= operations.length <= 10^5. Pushed values are 32-bit signed integers. Every pop, top, and getMin operation is issued on a nonempty stack.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a second stack that stores the minimum at each depth. On push x, append x to the main stack and append min(x, current min) to the min stack. On pop, remove from both. getMin just reads the top of the min stack. Every operation is O(1), and the total is O(n) over up to 10^5 operations. The pitfall is the single-variable minimum. Once you pop it, you've lost the previous one. Example 2 tests duplicates: push 2 twice, pop once, and the min must still be 2. Pushing the min on every push, not only when it changes, handles that for free. Watch parsing too. Split on a space and convert with a 32-bit safe integer parse, since negatives show up. Only pop, top, and getMin add to the output list. If your parsing or edge cases fall apart mid-OA, StealthCoder is the hedge that gets you unstuck.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Min 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as min stack. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass ZipRecruiter's OA.
ZipRecruiter reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Stack FAQ
What's the trick in the ZipRecruiter Min Stack problem?+
Keep a parallel stack where each entry is the minimum at that depth. Push the smaller of the new value and the current min every time. Pop both stacks together. getMin reads the top of the min stack in constant time, and duplicates are handled automatically.
Why does a single min variable fail?+
When you pop the current minimum, you need the previous one, and a lone variable has forgotten it. Example 1 shows it: after popping -3, the min must go back to -2. The parallel stack remembers every earlier minimum so nothing gets lost.
How hard is this one really?+
Easy on the algorithm side, with one catch. The data structure is a standard two-stack design. The extra work is parsing strings like "push -2" and collecting outputs only for pop, top, and getMin. Most failures come from the min logic or from forgetting to skip push in the output.
How should I handle duplicate minimum values?+
Push the min onto the min stack on every push, not only when a new smaller value arrives. Then two 2s give two entries of 2 in the min stack. Popping one leaves the other, so getMin still returns 2, matching Example 2.
How do I prepare for this in 48 hours?+
Write it from scratch twice without notes. Use two stacks, parse the operation strings, and test with both examples. Add a negative-number case and a duplicate-min case. Aim for O(1) per operation and a single output list. That covers what this problem actually tests.