Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

Solution: Evaluate Reverse Polish Notation

Problem Statement

Evaluate an arithmetic expression given in Reverse Polish Notation and return the integer result. Division truncates toward zero.

Examples

Example 1

  • Input: tokens = ["2", "1", "+", "3", "*"]
  • Expected Output: 9

Example 2

  • Input: tokens = ["4", "13", "5", "/", "+"]
  • Expected Output: 6

Example 3

  • Input: tokens = ["3", "-4", "*"]
  • Expected Output: -12

Why this is a stack problem

Reverse Polish Notation puts the operator after its two values, which is exactly why it needs no brackets

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content