Skip to content
QuantReadySign In
#004easyProbability

Birthday Collision

Problem

Given n people in a room, compute the probability that at least two of them share the same birthday.

Assume 365 equally likely birthdays (no leap years) and that birthdays are independent.

This is a classic result from probability theory and appears frequently in quant interviews as a warm-up to understanding the birthday paradox — the counterintuitive result that the probability exceeds 50% with only 23 people.

Input Format

A single integer n — the number of people.

Output Format

The probability rounded to 4 decimal places.

Examples

Example 1
Input(A single integer n — the number of people.)
23
Output
0.5073

With 23 people, the probability of a shared birthday first exceeds 50%.

Example 2
Input(A single integer n — the number of people.)
1
Output
0.0000

A single person cannot share a birthday with anyone.

Constraints

  • 1 ≤ n ≤ 365
  • Output rounded to 4 decimal places

Execution limits: 2s · 256MB

Loading interactive editor…