Practice

Problem 4 of 12

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

  1. Task 1, not checked yet. Make isBalanced pass the example tests.

  2. Task 2, not checked yet. Make isBalanced pass the hidden tests.

Task 1 of 2

Make isBalanced pass the example tests.

All tasks

main.js

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.