Evaluate Reverse Polish Notation
Problem
You are given a list of string tokens representing an arithmetic expression written in postfix (Reverse Polish) notation. Each token is either an integer (possibly negative) or one of the four operators +, -, *, /. Evaluate the expression and return the integer result.
Rules:
- Operators apply to the two most recently produced values, in the order they were produced (so
a b -meansa - b). - Division between integers truncates toward zero (so
-7 / 2is-3, not-4). - There is no division by zero.
- The expression is always valid.
Constraints:
- The token list has between 1 and 25,000 entries.
- Every integer token, and every intermediate value, fits in a signed 32-bit integer.
Examples
tokens = ["7", "3", "-", "5", "*"]→20. Computes(7 - 3) * 5.tokens = ["15", "2", "4", "*", "/"]→1. Computes15 / (2 * 4);15 / 8truncates to1.tokens = ["-9", "4", "/"]→-2.-9 / 4is-2.25, and truncation toward zero gives-2, not the-3that floor division would produce.
Hints
- In postfix notation, by the time you reach an operator, its operands have already been fully evaluated. Where are they?
- The two operands are the last two values you produced. Last-produced-first-consumed suggests a data structure.
- Push numbers on a stack; on an operator pop two, apply, push the result. The single remaining value is the answer.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.