Facebook Pixel
Evaluate Reverse Polish Notation
Medium

Given an array of strings tokens representing an arithmetic expression in Reverse Polish Notation (RPN), evaluate the expression and return the result.

Example:

Input: tokens = ["2","1","+","3","*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9

Input: tokens = ["4","13","5","/","+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6

Input: tokens = ["10","6","9","3","/","+","-11","*","/","17","+","5","+"]
Output: 22
Test Cases

Test Cases

Input
5
2
1
+
3
*
Expected Output
9
Step 1
Step 2
Step 3
Step 1: Identify the Pattern
Evaluate Reverse Polish Notation
Medium

Given an array of strings tokens representing an arithmetic expression in Reverse Polish Notation (RPN), evaluate the expression and return the result.

Example:

Input: tokens = ["2","1","+","3","*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9

Input: tokens = ["4","13","5","/","+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6

Input: tokens = ["10","6","9","3","/","+","-11","*","/","17","+","5","+"]
Output: 22
Test Cases

Test Cases

Input
5
2
1
+
3
*
Expected Output
9
Step 1
Step 2
Step 3
Step 1: Identify the Pattern