Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-183

Birthday Threshold Search

Problem

Smallest number of people n such that the probability of at least one shared birthday reaches target_prob, with days equally likely birthdays:

P(n) = 1 - product from i = 0 to n - 1 of (1 - i / days).

Return 0 for days <= 0 or target_prob outside (0, 1].

Hint

Grow the probability multiplicatively instead of recomputing the whole product.

Test cases

case 1
in: [365,0.5]
expected: 23
case 2
in: [365,0.99]
expected: 57
case 3
in: [365,0.01]
expected: 4
case 4
in: [1,0.5]
expected: 2
Starter codePython
def birthday_threshold(days, target_prob):
    # Your code here
    pass

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