Enough Muffins for the Line
Updated
Problem statement
A bakery has m muffins left, and n customers are waiting in line. Each customer buys exactly one item. Each customer wants a muffin with probability muffinPercent percent and otherwise wants a croissant, independently of everyone else. There are always enough croissants.
The customers are served one at a time. The muffins are enough if no customer wants a muffin after the muffins have run out.
Return the probability that the muffins are enough. Answers within 10^-9 of the exact value are accepted.
Function
enoughMuffinsProbability(n: int, m: int, muffinPercent: int) → doubleExamples
Example 1
n = 5m = 2muffinPercent = 30return = 0.83692This is the interview case. The muffins are enough when at most 2 of the 5 customers want one. No one wants a muffin with probability 0.7^5 = 0.16807. Exactly one wants a muffin with probability 5 * 0.3 * 0.7^4 = 0.36015. Exactly two want one with probability 10 * 0.3^2 * 0.7^3 = 0.3087. The answer is 0.16807 + 0.36015 + 0.3087 = 0.83692.
Example 2
n = 3m = 0muffinPercent = 50return = 0.125There are no muffins, so the muffins are enough only if none of the 3 customers wants one. That happens with probability 0.5^3 = 0.125.
Example 3
n = 4m = 1muffinPercent = 50return = 0.3125One muffin is enough when at most one of the 4 customers wants a muffin. Of the 16 equally likely want patterns, 1 has no muffin requests and 4 have exactly one. The answer is 5/16 = 0.3125.
Constraints
1 <= n <= 10000 <= m <= 10000 <= muffinPercent <= 100
More Susquehanna International Group (SIG) Online Assessment questions
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
- Knights, Knaves and Their StatementsOA · Seen Nov 2026
Similar questions at other companies
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Stable Workload Redistribution TreesTower Research Capital · OA
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
- Find Encrypted NumberAmazon · OA
- Valid PasswordsMathWorks · OAMathWorks interview questions
- Coloring HousesSnowflake · OASnowflake interview questions
- Find Maximum Number of StringsMoveworks · OAMoveworks interview questions
- Count Distinct Binary Search TreesC3.ai · OAC3.ai interview questions