AlgoFlow
intermediateStacks & Queues

Valid parentheses

Given a string containing only ( ) [ ] { }, determine whether it is valid: every opening bracket must be closed by the same type in the correct order.

Examples

input "{[()]}"

output true

Each bracket closes the most recent opener.

input "([)]"

output false

The brackets interleave instead of nesting.

input "((("

output false

Nothing ever closes — an underflow-free failure.

Hints

Try the problem first. Hints are revealed one at a time so you keep thinking.

Solution

The written approach, complexity analysis and follow-ups stay hidden until you ask for them.