GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many balanced parenthesis strings with 6 pairs have nesting depth at most 2?

  1. A. 42
  2. B. 64
  3. C. 32
  4. D. 132

Correct answer: C. 32

Without the restriction there are C₆ = 132 strings. With depth ≤ 2, a DP over positions and the current depth (0, 1 or 2) gives 32 = 2^(n−1); the unrestricted count is the Catalan number 132.

More Algorithms questions

Exams that ask this topic