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
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 ÷.
| Aspect | Value |
|---|---|
| Pattern | Stack / monotonic stack |
| Recognise it by | Postfix expression evaluation. |
| Time complexity | O(n) |
| Space complexity | O(n) |
| Difficulty | Medium |
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.