Code RoomSoup emptying probability
HardPrep Room Coding #1463

Soup emptying probability

CodingAlgorithms & data structuresSenior–Staff~35 min

There are two soups, A and B, each starting with n ml. On each turn one of four operations is chosen uniformly at random: serve (100,0), (75,25), (50,50), or (25,75) ml from (A,B); if a soup has less than the requested amount, serve all that remains. Operations continue until at least one soup is empty. Return the probability that soup A empties first, plus half the probability they empty simultaneously, rounded to 5 decimal places. 0 <= n <= 10^9.

Implement
soup_servings(n: int) → float
Examples
in[50]out0.625
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[50]0.625not run yetsample