Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, and /. Each operand may be an integer or another expression. Note that division between two integers should truncate toward zero.
30:00
Java
Evaluate Reverse Polish Notation
medium
Topics
Companies
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, and /. Each operand may be an integer or another expression. Note that division between two integers should truncate toward zero.
Example 1:
Input: {"tokens":["2","1","+","3","*"]}
Output: 9
Constraints:
1≤tokens.length≤104
Each token is either an operator +, -, *, /, or an integer in the range [−200,200].
Division between two integers truncates toward zero.
Input
arr ={"tokens":["2","1","+","3","*"]}
Start
Input
2
1
+
3
*
Stack (Indices)
Variables
No variables to display
DepthFunction Call
Stack empty
0/11
Asked in these interview guides
Company guides that list this problem among their sample questions.