I had this question asked in an interview:
In how many ways, we can construct binary search tree from \$n\$ elements?
I have written this code, but got a feedback that it could be improved. How to do it?
def count_ways(n):
c = [0] * (n+1)
c[0] = 1
c[1] = 1
for i in xrange(2, n+1):
sum_w = 0
for j in xrange(0, i):
sum_w += c[j] * c[i-j-1]
c[i] = sum_w
return c[n]
print count_ways(4)