Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-334

Committee Selection Probability

Problem

For a population with `good` acceptable members and `bad` others, the probability that a random committee of size k contains exactly g acceptable members is C(good, g) C(bad, k - g) / C(total, k).

Given total, good, k, and g, return the probability. Return 0.0 when the combination is impossible.

Hint

Multiply the two independent choices and divide by all committees.

Test cases

case 1
in: [10,6,3,2]
expected: 0.5
case 2
in: [10,6,3,0]
expected: 0.03333333333333333
case 3
in: [5,2,6,1]
expected: 0
Starter codePython
def committee_selection_probability(total, good, k, selected_good):
    # Your code here
    pass

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