FastPrepTwo Colors in Replacement Draws
Problems/Two Colors in Replacement Draws

Two Colors in Replacement Draws

IMC Trading logoIMC Trading● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad online assessment. The event that you get both colors in draws with replacement is about 95% the same as the reported question with five colors and four draws. The photo prints "nearest hundreds place" and separately gives .5 for 50%. We chose to round to the nearest hundredth. The counts can change, draws do not affect each other, halves round up, and we set limits and a tolerance. Those are our choices.

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) → double

Examples

Example 1

colorCount = 5drawCount = 4return = 0.31

The 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.50

Of the four sequences, red-green and green-red contain both distinguished colors.

Example 3

colorCount = 4drawCount = 2return = 0.13

Exactly 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 <= 10 and 0 <= drawCount <= 12.
  • Red and green are two different colors, each with probability 1/colorCount on 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

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public double bothColorsProbability(int colorCount, int drawCount) {
        // Write your solution here.
    }
}
Checking account…