All problems
Hypergeometric Moments Mean Variance
Problem
For n draws without replacement from N items with K successes, mean = n K / N and variance = n (K / N)(1 - K / N)(N - n) / (N - 1).
Given N, K, and n, return [mean, variance]. Assume N > 1.
Hint
The finite population correction shrinks the binomial variance.
Test cases
case 1
in: [10,4,3]
expected: [1.2000000000000002,0.56]
case 2
in: [20,10,5]
expected: [2.5,0.9868421052631579]
case 3
in: [100,25,10]
expected: [2.5,1.7045454545454546]
Starter codePython
def hypergeometric_mean_and_variance(n_population, k_successes, n_draws):
# Your code here
pass3 test cases · run your code against them in the editor