Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-168

Probability All Balls in Distinct Bins

Problem

Probability that balls thrown independently and uniformly into bins all land in distinct bins:

P = bins * (bins - 1) * ... * (bins - balls + 1) / bins^balls.

Return 0.0 when balls > bins or inputs are invalid.

Hint

This is the birthday-style no-collision probability.

Test cases

case 1
in: [2,2]
expected: 0.5
case 2
in: [3,6]
expected: 0.5555555555555556
case 3
in: [1,6]
expected: 1
case 4
in: [4,3]
expected: 0
Starter codePython
def probability_distinct_bins(balls, bins):
    # Your code here
    pass

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