All problems
Catalan Number
Problem
Compute the n-th Catalan number, which counts balanced bracket sequences and Dyck paths:
C_n = C(2n, n) / (n + 1).
Return 0 for negative n.
Hint
Use integer division after math.comb to stay exact.
Test cases
case 1
in: [0]
expected: 1
case 2
in: [3]
expected: 5
case 3
in: [5]
expected: 42
case 4
in: [10]
expected: 16796
Starter codePython
import math
def catalan_number(n):
# Your code here
pass4 test cases · run your code against them in the editor