Evaluate Reverse Polish Notation
Reported by candidates from Coalition's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Coalition OA, reported in March 2023, hands you Evaluate Reverse Polish Notation, and the thing that burns people is division. Integer division has to truncate toward zero, and in some languages the default operator floors instead. So -7 / 2 gives you the wrong answer and everything downstream breaks. The real pattern is a stack, not two pointers, despite the hint attached to this report. It's a short problem you can finish in minutes if you know the trap. If you blank on the live OA, StealthCoder runs invisibly as a safety net and gives you the working solution.
The problem
Evaluate an arithmetic expression in Reverse Polish Notation. Each operator consumes the two preceding values, and integer division truncates toward zero. Function evalRPN(tokens: String[]) → int Examples Example 1 tokens = ["2","1","+","3","*"] return = 9 Add 2 and 1, then multiply the result by 3. Constraints 1 <= tokens.length <= 10000 Tokens are integers or one of +, -, *, /. The expression is valid and no division uses zero.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Push each number onto a stack. When you hit an operator, pop twice. The first pop is the right operand, the second is the left. Compute left op right, then push the result back. At the end, the stack holds one value. That's the whole algorithm, linear time and linear space. The pitfalls are small but fatal. Order matters for subtraction and division, so swapping operands flips your answer. Truncation toward zero matters for negatives. In Python, use int(a / b) rather than a // b. In Java or C++, native division already truncates. Also parse tokens carefully, since negative numbers like "-3" aren't operators. Check the token against the four operator strings, not just its first character. The input is guaranteed valid with no zero divisors, so skip defensive checks. If the stack logic slips under pressure, StealthCoder is the hedge during the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Evaluate Reverse Polish Notation 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as evaluate reverse polish notation. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Coalition's OA.
Coalition reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Evaluate Reverse Polish Notation FAQ
What's the trick in Evaluate Reverse Polish Notation?+
Use a stack. Push numbers, and on an operator pop two values, apply the operation, and push the result. The real trick is operand order. The second pop is the left operand, so for subtraction and division you compute second minus first, not the reverse.
Why does my division answer fail on negative numbers?+
The problem says integer division truncates toward zero. Python's // floors, so -7 // 2 gives -4 instead of -3. Use int(a / b) in Python. Java and C++ already truncate toward zero, so plain division works there without changes.
Is this really a two-pointers problem?+
No. The report hinted two-pointers, but the structure is a stack. Each operator consumes the two most recent values, which is last-in-first-out behavior. Nothing here scans from both ends of an array. Treat it as a stack problem and you'll be fine.
How do I tell a negative number from the minus operator?+
Compare the whole token string. A token equal to "-" is the operator. A token like "-3" is a number. Checking only the first character is the classic bug. Test membership in the set of four operator strings, and parse everything else as an integer.
How should I prepare for this in 48 hours?+
Write it once from scratch in your OA language. Test with subtraction, division, and a negative result like ["4","-13","5","/","+"]. That covers the operand order and truncation traps. It's a 10-minute problem once those two details are locked in, so spend the rest on other patterns.