I need to define this function n_choose_k(n,k)
which returns the value of n choose k and number of recursive calls made as a tuple, while keeping in mind the following:
The number of recursive calls should not include the initial function call.
the function returns (-1,0) if:
- k is negative
- n is negative
- n is less than k
Here is what I have so far:
def n_choose_k(n, k):
if k == 0 or k == n:
return 1,0
elif n < k or k < 0 or n < 0:
return -1,0
return n_choose_k(n-1,k) + n_choose_k(n-1, k-1)
>>> print(n_choose_k(5,2))
(10, 18) ---> Expected
(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0) ---> Getting