16. Exactly k Heads in n Tosses

Medium

Choose which k of the n positions are heads, over all 2n2^n equally likely sequences:

P(exactly k heads)=(nk)2nP(\text{exactly } k \text{ heads}) = \frac{\binom{n}{k}}{2^n}

Return the probability as a float.

solve(3, 2)  ->  0.375      # HHT, HTH, THH out of 8
solve(5, 2)  ->  0.3125

Sign in to write and run your own code.

Implement solve(...)