Evaluate Reverse Polish Notation
Description
Given an array of strings tokens that represents an arithmetic expression in Reverse Polish Notation, evaluate the expression and return the integer result.
Valid operators are:
+ - * /
Each operand may be an integer or another expression.
Division between two integers should truncate toward zero.
Example 1
Input
5 2 1 + 3 *
Output
9
Explanation
(2 + 1) * 3 = 9
Example 2
Input
5 4 13 5 / +
Output
6
Explanation
4 + (13 / 5) = 4 + 2 = 6
Constraints
Hints:
Hint 1
Use a stack to store operands.
Hint 2
When you encounter an operator:
- Pop the second operand.
- Pop the first operand.
- Apply the operator.
- Push the result back onto the stack.
The final value remaining in the stack is the answer.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 9, 2026
Last updated
Aug 9, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output