Five minutes. One pattern. Stay fluent.

Daily etudes

Tag nest

Share task

Today’s task: “Tag nest”. Practice the Stack pattern! The string s contains only the brackets (), [] and {}. Return whether it is balanced: every opening bracket must have a matching closing bra... https://etuder.dev

The string s contains only the brackets (), [] and {}. Return whether it is balanced: every opening bracket must have a matching closing bracket of the same type, and pairs must be correctly nested. A closing bracket cannot appear without its opening bracket. The empty string is balanced.

Example:

is_balanced("([])")  →  True

The pair [] is fully enclosed by (). Both pairs match and are correctly nested.

is_balanced("([)]")  →  False

In ([)], ) closes the outer pair before ] closes the inner pair, so the nesting is invalid.

Pattern: stack — push openers; a closer must match the top