Check Balanced Brackets
Check Balanced Brackets
EasyStacks27% accepted
Given a string containing only ( and ), check if all brackets are properly balanced. Every opening bracket '(' must have a matching closing bracket ')' in the right order. Use a stack: push '(', pop when you see ')' — if you try to pop from an empty stack, it's unbalanced.
Approach
Given a string of '(' and ')', print 'Yes' if brackets are balanced, else 'No'.
Input
()
Output
YES
More Stacks problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards