Coffee Rank Probability
Updated
Problem statement
The classic 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 basic 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.
More Mercor interview questions
- Expected Fake-Name CollisionsPHONE SCREEN · Seen Oct 2026
- Length of a Document Reached Through a Random TokenPHONE SCREEN · Seen Oct 2026
- Precision of Stacked PII Detector FlagsPHONE SCREEN · Seen Oct 2026
- Sort by Checking PermutationsPHONE SCREEN · Seen Oct 2026
- CSV Row SerializerPHONE SCREEN · Seen Sep 2026
- Process Refunds with Bounded RetriesPHONE SCREEN · Seen Sep 2026
- Shortest Path in a Grid with Obstacles EliminationPHONE SCREEN · Seen Sep 2026
- Merge Sort Report with a Noisy ComparatorONSITE INTERVIEW · Seen Sep 2026
- Top K With a Deterministically Noisy Comparator (MLE)ONSITE INTERVIEW · Seen Sep 2026
- Minimum Friend API CallsONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Revolver: Will the Next Shot Fire?Tower Research Capital · PHONE SCREEN
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Painted Cube: Count and RollJane Street · PHONE SCREENJane Street interview questions
- One Number Is the Average of the Other TwoSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Count Routes Through a City GridIMC Trading · PHONE SCREENIMC Trading interview questions
- Extra Coin Win ProbabilityMicrosoft · PHONE SCREENMicrosoft interview questions
- Mean vs Median: Chance of Missing the CenterHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions