Evaluate Reverse Polish Notation

Given an array of operators and operands in reverse Polish notation, evaluate its value.

Statement

Given an array of operators and operands representing an arithmetic expression in reverse Polish notationIn this notation, the operators follow their operands, hence removing the need for brackets to define evaluation priority. Reverse Polish notation is also known as postfix notation., evaluate the expression and determine its value.

Note: Valid operators are +, -, *, and /. Each operand may be an integer or another expression.

Example

In the following example, we are given an array of operators and operands in reverse Polish notation which evaluates to 9, as we can see from the illustration below:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.