Suppose we have a number n. If we have numbers like [1,2,...,n] we have to count number ofpossible BSTs can be formed using these n values. If the answer is too large, then mod the result by 10^9+7.
So, if the input is like n = 3, then the output will be 14,
To solve this, we will follow these steps
Let us see the following implementation to get better understanding −
def solve(n): a = [0, 1] m = 10**9+7 max_n = 1000 for k in range(2, max_n + 2): a.append((1 + sum(a[i] * a[k - i] for i in range(1, k))) % m) return ((a[n + 1] - 1) % m) n = 3 print(solve(n))
3
14