Five minutes. One pattern. Stay fluent.
Daily etudes
Tag nest
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