← Stack

Pattern Recognition Drill

#21 — Valid parentheses string

Easy Stacks & Queues

The Problem

Check if a string of parentheses () is valid.

What approach would you use?

Think about it before scrolling down.

Key Signals

Stack

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.

← #20 #22 →