Combinatorics · Medium
A review coordinator chooses a panel of k people from n distinct eligible reviewers. Panel ordering is irrelevant. It needs an exact count without enumerating each possible group or rounding large factorial values.
Return the exact number of distinct unordered panels of size k drawn from n reviewers.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ n: integer, k: integer }
Fields
- n is the number of distinct reviewers. k is the requested number of reviewers on one panel.
Output
Return value
- Return C(n,k) as a safe JSON integer. Return 0 when k > n.
- Choosing nobody has one result: the empty panel. Reviewers cannot repeat in a panel.
Constraints
- 0 <= n <= 50; 0 <= k <= 50. All final counts fit exactly in JSON Number.
- Intermediate factorials do not fit in a safe Number; use exact integer arithmetic or a bounded recurrence.
Examples
Example 1
{
"k": 2,
"n": 5
}Returns
10Example 2
{
"k": 4,
"n": 3
}Returns
0Required complexity
O(min(k,n-k)) exact-integer steps and O(1) accumulators; return immediately when k > n