Combinations (n choose k)
EasyProbabilityMathSorting
Description
Given non-negative integers n and k, return the number of ways to choose k items from n without regard to order, the binomial coefficient C(n, k) = n! / (k! (n - k)!). Return 0 when k > n.
Examples
Input:
5, 2Output:
10Explanation:
Choosing k items from n while ignoring order counts each unordered group once, which is exactly the binomial coefficient.
Input:
5, 0Output:
1Explanation:
Choosing k items from n while ignoring order counts each unordered group once, which is exactly the binomial coefficient.
Input:
6, 3Output:
20Explanation:
Choosing k items from n while ignoring order counts each unordered group once, which is exactly the binomial coefficient.
Constraints
- •
0 ≤ k, n ≤ 30