Gamified challenge · Stacks
The vault code is a string of brackets ( ) [ ] { } and dial digits 0-9. Digits don't matter. The vault opens only if every opening bracket is closed by the same kind of bracket, and brackets close in the reverse order they were opened.
Write balanced(code) that returns true if the vault opens, else false. A code with no brackets at all (even an empty one) opens.
Examples: {1(2[3]4)5} opens. ([)] doesn't: the ) arrives while [ is still open. ((( doesn't either: nothing closes.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google