Min Stack
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reported this one in October 2022, and the detail that matters is in the second example: two pushes of 2, one pop, and the minimum is still 2. That's the whole question. It's Min Stack wrapped in a string-operations function that returns outputs for everything except push. If you've seen the classic, you're fine. If you blank on the duplicate case, you lose a clean pass. The pattern is a stack with a parallel minimum tracker, and it runs in O(1) per operation. StealthCoder sits invisibly on your screen as a safety net during the live OA if the stack bookkeeping slips out of your head.
The problem
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 to store the running minimum alongside each value. Keep a second stack, or push pairs of (value, minSoFar). On push, the new min is min(x, current min). On pop, you drop both, so the previous minimum comes back automatically. The classic pitfall is the duplicate case from Example 2. If your min stack only pushes when x is strictly less than the current min, a single pop of one 2 wipes out the minimum for the other 2. Push on less-than-or-equal, or use the pair approach and skip the problem entirely. Second pitfall: parsing. Split each string on the space, and remember negative numbers like -2 parse fine as integers. Only collect output for pop, top, and getMin. With 10^5 operations, anything that scans the stack for the minimum will time out. If the parsing or duplicate logic jams during the live OA, StealthCoder is the hedge that gives you the working version.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
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 Bloomberg's OA.
Bloomberg 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.
Min Stack FAQ
What's the trick in Bloomberg's Min Stack problem?+
Track the minimum at every depth of the stack. Store (value, minSoFar) pairs or keep a second stack of minimums. Every push records the min up to that point, so popping restores the previous min instantly. No scanning, no sorting, O(1) for every operation.
Why does Example 2 with two 2s matter?+
It tests duplicate minima. If your min stack only pushes on strictly smaller values, popping one 2 removes the minimum entirely and getMin breaks. Push the min whenever x is less than or equal to the current min, or use pairs so each element carries its own min.
How hard is this really?+
Easy if you've seen Min Stack before, a bit awkward if you haven't. The data structure is simple. The extra work here is parsing operation strings and collecting outputs only for pop, top, and getMin. Most failures come from output handling and the duplicate case, not the algorithm.
How should I parse the operations array?+
Loop over the strings. If it starts with push, split on the space and parse the second token as an integer, negatives included. Otherwise match the whole string against pop, top, or getMin. Append results to the output list only for those three. Push produces nothing.
How do I prepare for this in 48 hours?+
Write Min Stack from scratch twice. Once with a second stack, once with pairs. Then test the duplicate case and a negative-number case by hand. Add the string parsing wrapper last. That's about an hour of work, and it covers this problem plus its common variants.