Reported September 2026
Wexstack

Stack Command Output

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

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

Wex reported this one in September 2026, and it looks harmless until you read the constraints. The string can hit 10^5 characters, and you're parsing a tiny command language on a stack. It's a plain stack simulation: push on U, pop and record on O, stop at X. If your OA invite lands in the next day or two, this is a warm-up problem you can't afford to fumble on parsing. The logic takes five minutes. The whitespace handling is where people lose points. StealthCoder sits as a safety net on the live OA if your mind goes blank on the tokenizing.

The problem

Process a command string commands using an initially empty stack. Return the values removed by pop commands, in the order they are removed.
U value pushes the signed integer value onto the stack.
O removes the top value and appends it to the output.
X ends the command string. Values still on the stack are not output.
For this exercise, assume the input is valid: tokens are separated by one or more spaces, tabs, or newlines, optional whitespace may surround the string, exactly one X is the final token, and every O has a value available to pop. Integers use ordinary decimal notation with an optional leading minus sign.

Function
stackOutput(commands: String) → int[]

Examples
Example 1
commands = "U 3 U -3 O O X"
return = [-3,3]
Push 3, then -3. The first pop removes -3; the second removes 3.
Example 2
commands = "U 8 O U 4 U 9 O X"
return = [8,9]
The pops remove 8 and then 9. The remaining 4 is not output when X ends processing.

Constraints
1 <= commands.length <= 10^5.
There are at most 10^4 commands, including X.
Every pushed value is between -10^9 and 10^9, inclusive.
The command sequence satisfies the validity rules in the statement.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to tokenize once and walk the tokens with an index. Split on any whitespace run, not a single space, because the statement allows tabs, newlines, and multiple spaces. Then loop: if the token is U, read the next token as an integer and push it. If it's O, pop and append to the output list. If it's X, break. That's O(n) time and space, which easily covers 10^5 characters. Brute force isn't really tempting here, but re-scanning the string per command would be wasteful. The common pitfalls are splitting on a single space, forgetting that the value token follows U and must be consumed, and mishandling negative numbers by parsing character by character. Use your language's integer parser. Values fit in 32-bit range, so no overflow worry. If you blank mid-assessment, StealthCoder can hand you the loop while you check edge cases.

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 Stack Command Output 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

⏵ The honest play

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

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

Stack Command Output FAQ

How hard is the Wex Stack Command Output problem really?+

Easy. It's a direct stack simulation with a tiny command set. The only real friction is parsing, since whitespace can be spaces, tabs, or newlines. If you can push, pop, and split a string, you can finish this quickly and spend leftover time on edge cases.

What's the trick to this problem?+

Split the input on whitespace runs, then walk the tokens with an index. On U, consume the next token as a signed integer and push it. On O, pop into the output. On X, stop. Don't process anything after X, and don't output leftover stack values.

Do I need to worry about invalid input or an empty stack on pop?+

No. The statement guarantees valid input: exactly one X as the final token, and every O has a value to pop. You can skip defensive checks. Still, a quick guard doesn't hurt if you want clean code, but it isn't required for correctness.

What's the time complexity I should aim for?+

O(n) over the string length, with O(k) extra space for the stack and output where k is the number of commands, at most 10^4. Tokenizing once and processing in a single pass meets that. Nothing fancier than an array or list used as a stack is needed.

How do I prepare for this in 48 hours?+

Write it once in your OA language, including whitespace-robust splitting and integer parsing for negatives. Test the two examples plus a case with tabs and newlines. Then spend remaining time on other stack and parsing variants, since this pattern shows up often in simulation-style questions.

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

OA at Wex?
Invisible during screen share
Get it