Step 9 of 12 · Stacks
Balanced brackets
Problem
Read a string containing only (), [], and {}. Return "Balanced" when every opening bracket closes in the correct order, otherwise return "Not balanced".
Input
One non-empty string containing only bracket characters.
Output
The exact words "Balanced" or "Not balanced".
Examples
{[()]}Balanced
Every closing bracket matches the latest unmatched opening.
([)]
Not balanced
The pairs cross instead of closing in stack order.