Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the maximum nesting depth of parentheses in "(()(()))()"?

  1. A. 4
  2. B. 2
  3. C. 5
  4. D. 3

Correct answer: D. 3

Track the running balance and record its maximum; the deepest point comes inside the inner pair of the middle group. Counting all open brackets (last option) gives the total, not the depth.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic