Pattern Recognition Drill
Easy Stacks & Queues
The Problem
Evaluate a postfix (reverse Polish notation) expression.
What approach would you use?
Think about it before scrolling down.
Push numbers. On operator, pop two, apply, push result. Final stack element is the answer. O(n).
Common Trap
Watch operand order for non-commutative ops: second_popped OP first_popped (e.g., subtraction).