data-structures · intermediate · ~15 min
Compute the n-th Catalan number via DP.
Implement:
long long catalan(int n);
Return the n-th Catalan number (1, 1, 2, 5, 14, 42, ...). 0 <= n <= 33.
n in [0,33].
The n-th Catalan number.
Use long long; grows quickly.
#include <stddef.h>
/* The n-th Catalan number (C0=1, C1=1, C2=2, C3=5, ...). 0<=n<=33. */
long long catalan(int n){ (void)n; return 0; }
Off-by-one in the convolution indices.
C0 = 1.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.