Dsa
Stack
Warm-up
Max Scope Depth
In a custom programming language, scopes are defined by opening parentheses '(' and closing parentheses ')'. A valid program must have balanced parentheses. Your task is to find the maximum nesting depth of the scopes. If the parentheses are not balanced (e.g., '(()' or '())'), output -1.
Example:
Input: (())()(()(()))
Output: 3
Key concepts
stackcounters
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