FastPrepExtra Coin Win Probability

Extra Coin Win Probability

Microsoft logoMicrosoft● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Player A flips n + 1 independent fair coins, and player B flips n independent fair coins. Return the probability that A obtains strictly more heads than B.

Function

extraCoinWinProbability(n: int) → double

Examples

Example 1

n = 1return = 0.5

A's two coins beat B's one coin with probability one half.

Example 2

n = 100return = 0.5

The symmetry argument is independent of n.

Constraints

  • 0 <= n <= 10^9
  • Results use absolute tolerance 1e-12

More Microsoft problems

See Microsoft hiring insights
public double extraCoinWinProbability(int n) {
  // Write your code here.
}
n1
expected0.5
Checking account…