Question bank › Stack
Dsa Stack Hard

Nested Parentheses Count

Write a program to count the maximum depth of nested parentheses in a given string. The string may contain normal characters as well, but you should only count the depth of parentheses '()'. Print the maximum depth found. If there are no parentheses, print 0. Example: Input: (a(b(c)d)e) Output: 3

Key concepts

stackcountingnested structures

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.