Back to Practice
#0222
Balanced Brackets
MediumPython25 min20 XP
Problem
Return True if the string has balanced (), [], and {} brackets. Ignore all non-bracket characters.
Why This Matters
Balanced bracket logic shows up in parsers, expression validation, HTML-like checks, and stack interview problems.
Function Signature
def is_balanced_brackets(text):
Examples
Example 1
Input"a[(b + c) * {d}]"
OutputTrue
Every closing bracket matches the most recent unmatched opening bracket.
Constraints
- Return the exact requested value.
- Handle edge cases cleanly.
- Prefer readable Python before micro-optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input"a[(b + c) * {d}]"
ExpectedTrue
Every closing bracket matches the most recent unmatched opening bracket.
Hidden Test Categories
wrong nestingextra opening bracketextra closing bracket