Coffee Rank Probability
Problem statement
The reported question buys two coffees from shop A and two from shop B and asks for the probability that both A coffees taste better than both B coffees.
For this exercise, generalize the numbers of coffees to positive countA and countB. Assume all individual quality scores are independent draws from the same continuous distribution, so ties have probability zero and every ordering of the distinct coffees is equally likely.
Compute the probability that every coffee from A has a strictly higher score than every coffee from B. Return the exact reduced fraction as a string numerator/denominator, with no spaces. The original two-and-two question is the input countA = 2, countB = 2.
Function
coffeeWinProbability(countA: int, countB: int) → StringExamples
Example 1
countA = 2countB = 2return = "1/6"There are 4! equally likely labelled rankings. Exactly 2! * 2! put both A coffees above both B coffees, so the probability is 4/24 = 1/6.
Example 2
countA = 1countB = 2return = "1/3"The one A coffee must be the highest of three equally likely ranks. The probability is 1/3.
Constraints
1 <= countA, countB <= 10.- All coffees are individually distinct, with independent identically distributed continuous quality scores.
- Higher quality scores mean better taste; ties have probability zero.