Code Room
CodingHardcod-g900
Subject Probability dpLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.