Practice
Balanced Brackets Checker
2023/Oct/Nov·Variant 2
HARDStacks
A string contains only the characters ( and ). Use an array-based stack to check whether the brackets are balanced — every ( must have a matching ), closing brackets may never appear before their opener, and no bracket may be left unmatched at the end.
Input: One string of brackets.
Output: TRUE if balanced, FALSE otherwise.
Example:
Input: (())
Output: TRUE
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Nested brackets balance
Inputs: (())
Expected: TRUE
Test 2: Missing closing bracket
Inputs: (()
Expected: FALSE
Test 3: Closing bracket before any opener
Inputs: )(
Expected: FALSE