← All Patterns

Pattern Recognition Drill

#134

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.

Evaluate Reverse Polish Notation

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 #135 →