Two Colors in Replacement Draws
Updated
Problem statement
A bag contains colorCount equally likely colors, including distinct red and green colors. Draw a marble drawCount times, replacing it after every draw. Find the probability that both red and green appear at least once.
For this exercise, assume the replacement draws are independent, and generalize the five-color, four-draw case in the first example to the supplied counts. Return the probability rounded to the nearest hundredth as a numeric decimal. For this exercise, assume exact halfway values round upward, so 0.125 becomes 0.13.
Zero draws give probability zero. For this exercise, assume relative-or-absolute numeric tolerance 1e-9 for the already rounded result. Complete bothColorsProbability(colorCount, drawCount).
Function
bothColorsProbability(colorCount: int, drawCount: int) → doubleExamples
Example 1
colorCount = 5drawCount = 4return = 0.31The five-color, four-draw case has 5^4 = 625 draw sequences. Exactly 625 - 2×256 + 81 = 194 contain both red and green. The probability 0.3104 rounds to 0.31.
Example 2
colorCount = 2drawCount = 2return = 0.50Of the four sequences, red-green and green-red contain both distinguished colors.
Example 3
colorCount = 4drawCount = 2return = 0.13Exactly two of sixteen sequences contain both colors. The exact probability is 0.125; the declared half-up convention gives 0.13.
Constraints
- For this exercise, assume
2 <= colorCount <= 10and0 <= drawCount <= 12. - Red and green are two different colors, each with probability
1/colorCounton each draw. - All exact sequence counts and the integer half-up rounding numerator fit a signed 64-bit integer under these bounds.
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Enough Muffins for the LineSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Subarray SumVisa · OAVisa interview questions
- Drawing EdgeWeRide · OAWeRide interview questions
- Drawing EdgeIBM · OAIBM interview questions
- Drawing EdgeSnowflake · OASnowflake interview questions
- Process SchedulingCitadel · OACitadel interview questions
- Unique Digits in RangeAgoda · OAAgoda interview questions
- Find Max Number of PairsRoblox · OARoblox interview questions
- Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions