LC 150
LeetCode 150 · Medium

Evaluate Reverse Polish Notation

Evaluate an arithmetic expression given in Reverse Polish Notation.


Try it

Step through the core mechanic. The simulator below runs the stack / monotonic stack shape this problem is built on.

Interactive · bracket matching push openers, pop on a matching closer
input
(
[
]
{
}
)
stack
empty
empty stack
step 1 / 8

The approach

Push numbers; on an operator, pop two operands, apply, push the result. The single remaining value is the answer. Mind operand order for − and ÷.

AspectValue
PatternStack / monotonic stack
Recognise it byPostfix expression evaluation.
Time complexityO(n)
Space complexityO(n)
DifficultyMedium

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.