Katkat

Find the Probability That One Shop Supplies the Top Two Coffees

MercorSoftware Engineer · Technical Screen

Last updated

Calculate the probability that the top-ranked coffees in a blind competition come from the same shop under an exchangeable, tie-free ranking model.

Problem Description

Two specialty roasters, Shop A and Shop B, participate in a blind coffee tasting competition. Each shop submits coffees to be evaluated by a panel of judges. The judges produce a strict, complete ranking of all submitted coffees from best (rank 1) to worst, with no ties permitted.

Assume an exchangeable null model: all submitted coffees are identically distributed in perceived quality, meaning every possible ranking of the coffees is equally likely.

Part 1: Equal 2-Coffee Submission

Suppose Shop A submits exactly 2 coffees and Shop B submits exactly 2 coffees (4 coffees total).

  1. What is the probability that one shop supplies the top two coffees in the competition (i.e., both coffees from one shop outrank both coffees from the other shop)?
  2. Show your derivation using both permutation counting (total orderings) and combination counting (subset of rank positions).

Part 2: General Case for Top Two

Suppose Shop A submits a coffees and Shop B submits b coffees, where a >= 2 and b >= 2.

  1. Derive a closed-form formula for the probability that the top two coffees (ranks 1 and 2) both come from Shop A.
  2. Derive a closed-form formula for the probability that the top two coffees come from the same shop (either both from A or both from B).
  3. Verify that your formula matches the result from Part 1 when a = 2 and b = 2.

Part 3: Total Dominance

For arbitrary a >= 1 and b >= 1, compute the probability of "total dominance"—that is, every coffee from one shop is ranked strictly higher than every coffee from the other shop.

Hints

Hint 1

Focus on the identities of the shops occupying the first two rank positions rather than the full permutation of all coffees.

Hint 2

By symmetry, the probability of shop A taking rank 1 is a / (a + b), and conditional on that, the probability of shop A also taking rank 2 is (a - 1) / (a + b - 1).

Hint 3

For total dominance, only two valid configurations of shop assignments exist: all of shop A followed by all of shop B, or vice versa, out of (a + b) choose a possible shop sequences.

Follow-up questions

  • How does the probability in Part 2 change if there are k shops, each submitting n coffees?
  • If ties are allowed with a known tie-breaking probability distribution, how would you reformulate the exchangeability condition?
  • How could this calculation be used as a non-parametric hypothesis test (permutation test) against the alternative that Shop A produces superior coffee?