Problem
You get an array of strings tokens. The tokens make an arithmetic expression in Reverse Polish Notation (RPN). In RPN, each operator comes after its two operands.
An operand is a value that an operator uses. It can be an integer token or the result of an earlier operation. For example, the tokens ["3", "4", "2", "-", "*"] mean 3 * (4 - 2).
Each token is an integer or one of the operators +, -, * and /. The division of two integers rounds toward zero.
Return the value of the expression as an integer. The input is always a valid expression. It never divides by zero, and all the results fit in a 32-bit integer.
Example 1
- Input:
- tokens = ["7","3","-","5","*"]
- Output:
- 20
- Explanation:
- The expression is
(7 - 3) * 5, which is 20.
Example 2
- Input:
- tokens = ["-7","2","/"]
- Output:
- -3
- Explanation:
- The exact value of
-7 / 2is -3.5. The division rounds toward zero, so the result is -3.
Example 3
- Input:
- tokens = ["6","2","8","3","-","*","+"]
- Output:
- 16
Constraints
- 1 <= tokens.length <= 10^4
- tokens[i] is an operator (+, -, * or /) or an integer in the range [-200, 200].
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- 132 Pattern
Coding · Array · Binary Search · Monotonic Stack
- Add Two Numbers II
Coding · Linked List · Math · Stack
- Asteroid Collision
Coding · Array · Simulation · Stack
- Basic Calculator II
Coding · Math · Stack · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Google
Leetcode 150. Evaluate Reverse Polish Notation
Reported Nov 4, 2024 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 3 records
Citadel
Evaluate Reverse Polish Notation
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 100. This is not an interview probability.
View sourceCitadel
Evaluate Reverse Polish Notation
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 77.4. This is not an interview probability.
View sourceCitadel
Evaluate Reverse Polish Notation