Question bank › Stack
Dsa Stack Hard

Balanced Pairs in Nested Structures

You are given a complex string that consists of pairs of characters representing nested structures. For example, 'a(b(c))' represents a nesting of 'a', 'b', and 'c'. Your goal is to find the maximum depth of nesting in the string. A pair is defined as a character followed immediately by its matching closing character. Please write a program that takes such a string as input and outputs the maximum nesting depth. Input Format: A single line string composed of characters and pairs. Output Format: An integer representing the maximum depth of nesting. Example: Input: a(b(c)d(e)) Output: 3

Key concepts

stackpairsnested

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.