← Stack

Pattern Recognition Drill

#134 — Evaluate Reverse Polish Notation

Medium Stacks & Queues

The Problem

Evaluate an arithmetic expression in Reverse Polish Notation (postfix).

What approach would you use?

Think about it before scrolling down.

Key Signals

Stack

Push numbers. On operator, pop two, compute, push result. O(n).

Common Trap

Division truncates toward zero in RPN. In Python, use int(a/b) not a//b (which floors).

← #133