Binomial Probability

MediumProbabilityMath

Description

Given the number of trials n, a number of successes k, and a success probability p, return the binomial probability of exactly k successes: C(n, k) * p^k * (1 - p)^(n - k). Round the result to 4 decimal places.

Examples

Input:5, 2, 0.5
Output:0.3125
Explanation:

The binomial probability multiplies the number of ways to place k successes by the chance of those successes and of the remaining failures.

Input:10, 0, 0.3
Output:0.0282
Explanation:

The binomial probability multiplies the number of ways to place k successes by the chance of those successes and of the remaining failures.

Input:4, 2, 0.25
Output:0.2109
Explanation:

The binomial probability multiplies the number of ways to place k successes by the chance of those successes and of the remaining failures.

Constraints

  • 0 ≤ k ≤ n ≤ 30
  • 0 ≤ p ≤ 1

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.