← Back to challenges

Balanced Brackets

PythonHardlogicstringsvalidation

Instructions

Write a function that takes a string of brackets and checks whether they're balanced or not.

The sequence is balanced if:

  • It contains no unmatched brackets.
  • The subset of brackets enclosed within the confines of a matched pair of brackets is also balanced.

Examples

isBalanced("{[()]}") ➞ True

isBalanced("[()]{}") ➞ True

isBalanced("{[([)]]}") ➞ False

Notes

Return None if no input is given.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.