All problems
Negative Binomial PMF
Problem
Negative binomial probability mass function: probability that the r-th success occurs on trial k.
P(X = k) = C(k - 1, r - 1) * p^r * (1 - p)^(k - r) for k >= r >= 1. Return 0.0 otherwise.
Hint
Arrange r - 1 successes among the first k - 1 trials, then succeed again.
Test cases
case 1
in: [1,0.5,3]
expected: 0.125
case 2
in: [2,0.5,4]
expected: 0.1875
case 3
in: [3,0.3,5]
expected: 0.07937999999999998
case 4
in: [2,0.5,1]
expected: 0
Starter codePython
import math
def negative_binomial_pmf(r, p, k):
# Your code here
pass4 test cases · run your code against them in the editor