Skip to content

Practice Soup Servings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#808
LeetCode Problem

Soup Servings

Problem Statement

Soups A and B each begin with n millilitres. Each turn independently chooses one of four equally likely simultaneous servings: (100, 0), (75, 25), (50, 50) or (25, 75) millilitres from (A, B). If a serving exceeds the amount remaining, serve all that remains. Stop after the first turn that empties either soup. Return the probability A empties first plus half the probability both empty together. Absolute error up to 10^-5 is accepted.

Source: Soup Servings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 50
Output
0.62500

# Example 2

Input
n = 100
Output
0.71875

Constraints

0 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Soup Servings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.