Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-238

Negative Binomial Expected Trials

Problem

For a negative binomial distribution that counts the number of trials until r successes, with success probability p, the expected number of trials is r / p. Return 0.0 when r < 1 or p is outside (0, 1].

Hint

Each success takes a geometric number of trials, so multiply the mean by r.

Test cases

case 1
in: [3,0.5]
expected: 6
case 2
in: [5,0.2]
expected: 25
case 3
in: [1,0.25]
expected: 4
case 4
in: [0,0.5]
expected: 0
case 5
in: [2,0]
expected: 0
Starter codePython
def negative_binomial_expected_trials(r, p):
    # Your code here
    pass

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