Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many Dyck words (balanced bracket sequences) of length 10 exist? Run the DP.

Problem: How many Dyck words (balanced bracket sequences) of length 10 exist? Run the DP.
n = 5
C = [1] + [0] * n
for m in range(1, n + 1):
    C[m] = sum(C[i] * C[m - 1 - i] for i in range(m))
print(C[n])
What is printed?
  1. A. 252
  2. B. 50
  3. C. 14
  4. D. 42

Correct answer: D. 42

Dyck words of length 10 are Catalan(5) = C(10,5)/6 = 42. 252 = C(10,5) ignores balance, dividing by n instead of n + 1 gives 50, and 14 is Catalan(4).

More Coding Interview Problems questions

Exams that ask this topic