FastPrepRed Balls Swapped for Blue
Problems/Red Balls Swapped for Blue

Red Balls Swapped for Blue

Susquehanna International Group (SIG) logoSusquehanna International Group (SIG)● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A new grad report from January 2024 describes a first SIG quant phone round, which the author later says was the HR round. One of its questions: a bag starts with two red balls and one blue ball, and every ball that is drawn gets swapped for a blue one. Find the expected number of draws until both red balls are gone. The author says every answer was accepted, but the round still ended in a rejection.

The report gives one bag only and no input format. Here, the number of balls n (up to 10^9) and the number of red balls r (up to 10^6) are inputs, and the function returns the expected number of draws. The interview bag is the first example. Answers within 10^-9 (absolute or relative) are accepted.

Our version is about 85% the same as the reported question.

A bag holds n balls. r of them are red and the rest are blue.

You repeat one step: draw a ball uniformly at random from the bag, set it aside, and put one new blue ball into the bag. So the bag always holds n balls, and a red ball that has been drawn never comes back.

Return the expected number of draws until no red ball is left in the bag.

Your answer is accepted if its absolute error or its relative error is at most 10^-9.

Function

expectedDrawsToClearRed(n: int, r: int) → double

Examples

Example 1

n = 3r = 2return = 4.5

This is the interview bag: 2 red balls and 1 blue ball.

While 2 reds are left, a draw picks a red with chance 2/3, so on average it takes 3/2 draws to remove the first red. Then 1 red is left and each draw picks it with chance 1/3, which takes 3 draws on average. The answer is 3/2 + 3 = 4.5.

Example 2

n = 5r = 1return = 5.0

One red ball among 5. Each draw picks it with chance 1/5, and draws that pick a blue ball change nothing. The wait for an event with chance 1/5 per try is 5 tries on average.

Example 3

n = 4r = 4return = 8.333333333333334

All 4 balls start red. The waits are 4/4, 4/3, 4/2 and 4/1 as the reds go from 4 down to 1. Their sum is 1 + 4/3 + 2 + 4 = 25/3, about 8.3333.

Constraints

  • 1 <= r <= 10^6
  • r <= n <= 10^9

More Susquehanna International Group (SIG) Phone Screen questions

  • Dice Sum That Is a Multiple of mPHONE SCREEN · Seen Nov 2026
  • Find Median from Data StreamPHONE SCREEN · Seen Nov 2026
  • Painting Arcs to Nearest Neighbors on a CirclePHONE SCREEN · Seen Sep 2026
  • Filter Movies by Inclusive Year RangePHONE SCREEN · Seen Jul 2026
  • Best Single Reroll for Five DicePHONE SCREEN · Seen Feb 2026
  • Catching the Bus to the MoviePHONE SCREEN · Seen Jan 2026
  • Two Dice Summing to a TargetPHONE SCREEN · Seen Jan 2026
  • Median of Uniform Draws in an IntervalPHONE SCREEN · Seen Oct 2025
  • One Number Is the Average of the Other TwoPHONE SCREEN · Seen Jun 2025
  • Which Coin Pattern Shows Up FirstPHONE SCREEN · Seen May 2025

Similar questions at other companies

  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Circular Primes Below a LimitAmazon · PHONE SCREEN
  • Palindrome NumberKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • Streaming AverageXantium · PHONE SCREEN
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Newton Square Root to a Guaranteed ToleranceSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions

Interview reports that mention this question

  • SIG Quant Research Intern Interviews: 60 Experiences
  • SIG Quant Researcher New Grad Interviews: 49 Experiences

Susquehanna International Group (SIG) interview experiences

  • SIG Quant Researcher Experienced Hire Interviews: 11 Experiences
  • SIG Quant Researcher Intern Interviews: 1 Experience
  • SIG Quant Second-Round Tech Screen: 1 Experience
All Susquehanna International Group (SIG) interview questionsSee Susquehanna International Group (SIG) hiring insights
Saved
class Solution {
    public double expectedDrawsToClearRed(int n, int r) {
        // Write your code here.
    }
}
Checking account…