← back to unit
Medium
# stacks medium
The Bracket Inspector
Every opening bracket needs a closing partner, in the right order — the inspector checks. 🧐
You get a string code of only ( and ) characters. Print balanced if every bracket pairs up properly, otherwise broken. (Careful: )( has one of each but is still broken!)
Example:
Input: code = "(())()"
Output: balanced
Pushing each ( and popping on each ) empties the stack exactly at the end — every bracket pairs up correctly.
💡 need a hint?
stk-bracket-inspector.py🔒 given lines are locked — write your code in between
loading...