Ctrl K

Which Pot Runs Dry First

Medium
A canteen has two pots of soup, A and B, each holding volume ml. The cook serves portions, each time picking one of four ladles at random with equal probability 1/4: - 100 ml from A and 0 ml from B; - 75 ml from A and 25 ml from B; - 50 ml from A and 50 ml from B; - 25 ml from A and 75 ml from B. If a pot holds less than the ladle calls for, whatever is left is poured out. Serving stops as soon as at least one pot is empty. Return the probability that A runs dry before B, plus half the probability that both run dry at the same time. Answers within 10⁻⁵ of the exact value are accepted.
Example 1
volume=25 → 0.625

Every ladle empties pot A. In three cases out of four pot B empties at the same moment (counted as one half); with the 100/0 ladle B still has soup: 0.25 · (1 + 0.5 + 0.5 + 0.5) = 0.625.

Example 2
volume=75 → 0.65625

Now several servings can happen in a row; summing over all outcomes with their probabilities gives 0.65625.

Example 3
volume=0 → 0.5
Constraints
  • 0 ≤ volume ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsChance of Not Going Over MediumLast Viewer in the Right Seat MediumOdds of Exactly That Many Heads MediumA Fair Split of Colored Beads HardCounting Grid Routes Medium
loading Python…
Input
volume=25
Expected
0.625

Run checks the first 3 tests in your browser. Submit checks all 55 tests on the server, hidden ones included.