AlgoViz
← All drills
🧠 Drill · Think it through

Whatever you opened last, close it first

The problem

You're given a string of brackets using three kinds — round (), square [], and curly {}. Return whether they're validly nested: every closer matches the most recently opened bracket of its kind, and nothing is left open at the end. So "([])" is valid but "([)]" is not.

Don't jump to code. Walk the four questions an expert asks first — you'll build the habit, not just the answer.

1

Restate it

Before anything else — did you read what's actually being asked? Strip the story to the bare goal.

Strip away the symbols. What does 'validly nested' actually require?