Evaluate Reverse Polish Notation
Problem Statement
Given the Reverse Polish Notation (RPN) of an arithmetic expression as an array of strings, evaluate the expression.
Reverse Polish Notation is a mathematical notation where operators follow their operands. The expression is evaluated by applying the operators from left to right.
Input Constraints
- The input will be an array of strings
expressionsandnums, representing the arithmetic expression in Reverse Polish Notation.operations - The input will only contain the four basic arithmetic operators:
expressions,+,-,*./ - The input will not contain any invalid characters or invalid operations.
expressions - The input will only contain positive integers as operands.
expressions - The input will always form a valid arithmetic expression.
expressions
Output Constraints
- The function should return the result of the arithmetic expression as a floating-point number.
- The result should be accurate up to four decimal places.
Time and Space Complexity
- The function should have a time complexity of O(n), where n is the number of operations in the input array.
- The function should have a space complexity of O(n), where n is the number of operations in the input array.
Assumptions
- The input will always contain a valid stack-based RPN expression.
expressions - The input will never contain any invalid characters or invalid operations.
expressions
Example
Input: {"tokens":["2","1","+","3","*"]} Output: 9
CompaniesAmazon
JavaScript
Login to write code
Solve problems, verify your skills, and earn XP.