Catalan Number

MediumMathDynamic ProgrammingSQL

Description

Return the n-th Catalan number C_n = (2n)! / ((n+1)! * n!).

Examples

Input:n = 0
Output:1
Explanation:

By convention, the 0th Catalan number C_0 equals 1.

Input:n = 5
Output:42
Explanation:

C_5 is the classic value 42, the number of ways to triangulate a heptagon.

Input:n = 10
Output:16796
Explanation:

C_10 evaluates to 16796, a standard Catalan-number table entry.

Constraints

  • 0 ≤ n ≤ 30

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.