Balanced brackets
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
Loading the editor…
Run the tests to check your solution.