Pattern Recognition Drill
Easy Stacks & Queues
The Problem
Check if a string of parentheses () is valid.
What approach would you use?
Think about it before scrolling down.
Push '(' on open, pop on ')'. If stack empty when popping or non-empty at end → invalid. O(n).
Common Trap
A simple counter (increment on open, decrement on close) works here but doesn't extend to mixed bracket types.