Evaluate Reverse Polish Notation
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

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≤1041 \leq \text{tokens.length} \leq 10^4

  • Each token is either an operator +, -, *, /, or an integer in the range [−200,200][-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.