Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-356

Negative Binomial Moments Mean Variance

Problem

For failures before the r-th success with success probability p, mean = r (1 - p) / p and variance = r (1 - p) / p^2.

Given r and p, return [mean, variance].

Hint

It is a sum of r geometric failure counts.

Test cases

case 1
in: [2,0.5]
expected: [2,4]
case 2
in: [1,0.2]
expected: [4,19.999999999999996]
case 3
in: [5,0.8]
expected: [1.2499999999999996,1.5624999999999993]
Starter codePython
def negative_binomial_mean_and_variance(r, p):
    # Your code here
    pass

3 test cases · run your code against them in the editor