Problem · Medium · 20 min
Balanced brackets
- Medium
- Stacks
- Strings
A text can hold three kinds of brackets: (), [] and {}. The text is balanced when every opening bracket has a closing bracket of the same kind, and the pairs do not cross each other.
Write isBalanced(text). It returns true when the text is balanced, and false when it is not.
- Ignore all characters that are not brackets.
- A text with no brackets is balanced.
"([])"is balanced."([)]"is not, because the pairs cross."(("is not, because two brackets stay open.
Examples
| Call | Result |
|---|---|
isBalanced('([]){}') |
true |
isBalanced('([)]') |
false |
isBalanced('((') |
false |
Tasks
2 to do
Task 1, not checked yet. Make
isBalancedpass the example tests.Task 2, not checked yet. Make
isBalancedpass the hidden tests.
Task 1 of 2
Make isBalanced pass the example tests.