CodeMIRAI
0 XP

Balanced brackets

Hard +80 XP Solved

Read a line containing only the characters ()[]{}. Print balanced if every bracket is closed by the same type of bracket in the correct order, otherwise print unbalanced.

([]{}) is balanced; ([)] is not.

Input
([]{})
Expected output
balanced
Input
([)]
Expected output
unbalanced
Show a hint

Push opening brackets onto a stack. Each closing bracket must match the one on top of the stack.

Show a solution
JavaScript
Loading the editor…
Run the tests to check your solution.