Probability of At Least One Success in n Independent Trials

Basics
BasicsComplement RuleGoogleMetaJane Street

Problem

Each independent trial succeeds with probability p. Implement at_least_one_success(p, n) returning the probability of at least one success in n trials: 1−(1−p)n1 - (1 - p)^n.

Why It Matters: This formula drives LLM pass@k code-generation benchmarks, retry reliability engineering, and classic dice/gambling interview questions.

Function Signature

def at_least_one_success(p: float, n: int) -> float:

Sample Input & Output

Example 1: 50% Success Over 3 Trials

Input:

p = 0.5, n = 3

Expected Output:

0.875

Explanation: Probability all 3 fail is 0.5^3 = 0.125, so at least one succeeds with 1 - 0.125 = 0.875.

Example 2: Rare Event Over 5 Retries

Input:

p = 0.2, n = 5

Expected Output:

0.67232

Explanation: 1 - 0.8^5 = 1 - 0.32768 = 0.67232.

Constraints & Edge Cases

  • Return a float in [0, 1].
  • Guaranteed 0.0 <= p <= 1.0 and n >= 0.
  • When n = 0, returns 0.0 (1 - 1 = 0).

Constraints & Evaluation Criteria

  • Return a float in `[0, 1]`.

Hints

Python 3
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
p=0.5, n=3
Expected Output / Criteria
0.875