All problems
Expected Birthday Collisions
Problem
Expected number of colliding pairs among n people whose birthdays are uniform over days days:
E[pairs] = C(n, 2) / days.
Return 0.0 for n < 2 or days <= 0.
Hint
Use indicators for each pair and linearity of expectation.
Test cases
case 1
in: [23,365]
expected: 0.6931506849315069
case 2
in: [2,365]
expected: 0.0027397260273972603
case 3
in: [57,365]
expected: 4.372602739726028
case 4
in: [1,365]
expected: 0
Starter codePython
def expected_birthday_collisions(n, days):
# Your code here
pass4 test cases · run your code against them in the editor