Dsa
Stack
Medium
Parenthesis Balancer
You are tasked with verifying if a series of expressions containing parentheses are balanced. An expression is considered balanced if every opening parenthesis has a corresponding closing parenthesis. The input consists of multiple lines, with each line being an expression. You should output 'YES' for balanced expressions and 'NO' for unbalanced ones.
Example input:
(()())
(())
(()
)(
Output:
YES
YES
NO
NO
Key concepts
stackvalidationparentheses
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now