Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-029

Birthday Problem Probability

Problem

Probability that at least two of n people share a birthday, assuming days equally likely birthdays.

P(shared) = 1 - product from i = 0 to n - 1 of (1 - i / days). Return 0.0 for n <= 1 and 1.0 when n > days.

Hint

Complement of all birthdays being distinct.

Test cases

case 1
in: [23,365]
expected: 0.5072972343239854
case 2
in: [1,365]
expected: 0
case 3
in: [2,365]
expected: 0.002739726027397249
case 4
in: [23,1]
expected: 1
case 5
in: [57,365]
expected: 0.9901224593411699
Starter codePython
def birthday_probability(n, days):
    # Your code here
    pass

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