Loading...
Loading...
Loading...
The number of ways to choose k items from n is C(n, k). It follows the rule C(n, k) = C(n-1, k-1) + C(n-1, k), with C(n, 0) = C(n, n) = 1. Use a cached recursion to print it.
Example
Input
5 2
Output
10
Ten ways to pick 2 of 5.
Try the problem first. Open one hint at a time.
The base cases are k = 0 and k = n.
Add the answers for (n - 1, k - 1) and (n - 1, k).
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor