Catalan Number
MediumMathDynamic ProgrammingSQL
Description
Return the n-th Catalan number C_n = (2n)! / ((n+1)! * n!).
Examples
Input:
n = 0Output:
1Explanation:
By convention, the 0th Catalan number C_0 equals 1.
Input:
n = 5Output:
42Explanation:
C_5 is the classic value 42, the number of ways to triangulate a heptagon.
Input:
n = 10Output:
16796Explanation:
C_10 evaluates to 16796, a standard Catalan-number table entry.
Constraints
- •
0 ≤ n ≤ 30