Evaluate Reverse Polish Notation

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Evaluate Reverse Polish Notation

Approach

Use a stack to process tokens. Push numbers directly. For operators, pop the top two numbers, apply the operation in order (first popped is right operand), and push the result back.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Stack Evaluation

Why It Works

RPN places operators after their operands, so by the time an operator is seen, both required operands are on top of the stack and can be reduced into one value.

Updated Feb 2026