Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Evaluate Reverse Polish Notation in Javascript


Input: [“3”, “1”, “+”, “5”, “*”]
Output: 9
Explanation: ((3 + 1) * 5) = 20


Algorithm:

The key thing to realize in this to use stack as a data structure for the solution. Also, in most of the mathematical operations stack is used.

  • Push operands to stack until you encounter an operator
  • When you encounter an operator, pop two operands from stack
  • Calculate operands using given operator and push the result to the stack

Solution:


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *