Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-350

Negative Binomial PMF Value

Problem

For the number of failures K before the r-th success, P(K = k) = C(k + r - 1, k) (1 - p)^k p^r.

Given r, p, and k, return the probability.

Hint

The last trial is a success; the rest array r - 1 successes among k failures.

Test cases

case 1
in: [2,0.5,1]
expected: 0.25
case 2
in: [1,0.2,3]
expected: 0.10240000000000003
case 3
in: [3,0.6,0]
expected: 0.21599999999999997
Starter codePython
def negative_binomial_pmf_value(r, p, k):
    # Your code here
    pass

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