FastPrepExpected Draws to Remove All Green Counters
Problems/Expected Draws to Remove All Green Counters

Expected Draws to Remove All Green Counters

Optiver logoOptiver● MediumFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 account by a candidate who sat Optiver's quant researcher online test (full-time role) closes with a batch of probability exercises; our problem takes the jar exercise from that batch.

The jar there has 9 blue and 3 green counters. Counters come out at random and are not returned, and drawing ends once the third green one is out; the question is how many draws that takes on average. The post does not give the answer.

What we added: both counts became inputs (blue from 0 to 10^9, green from 1 to 10^9, where the report has 9 and 3); the draw that takes the last green counter counts as a draw; results are decimals, and a relative gap from the exact value of 10^-9 or less is allowed. The reported jar is used as Example 1; the size limits and the two smaller examples are our additions.

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

A jar contains blue blue counters and green green counters. You remove counters from the jar one by one. On each draw, every counter still inside the jar has the same chance of being the one you take, and a counter that has been taken stays out.

Drawing ends with the draw that leaves no green counter in the jar; any blue counters still inside at that moment are never drawn. Return how many draws you make on average, including that final draw.

Function

expectedDrawsUntilAllGreen(blue: int, green: int) → double

Examples

Example 1

blue = 9green = 3return = 9.75

As a fraction this is 39/4. Each of the 9 blue counters has a 3/4 chance of being drawn before the third green one, so on average 27/4 blue counters come out along with the 3 green ones.

Example 2

blue = 2green = 2return = 3.3333333333333335

The 6 orders of the colors are equally likely. BBGG needs 4 draws, BGBG 4, GBBG 4, BGGB 3, GBGB 3 and GGBB 2, so the mean is 20/6 = 10/3.

Example 3

blue = 5green = 1return = 3.5

Each of draws 1 to 6 takes the single green counter with chance 1/6, so the mean is 3.5.

Constraints

  • 0 <= blue <= 10^9
  • 1 <= green <= 10^9
  • Answers are checked with tolerance: |output - exact| <= 10^-9 · exact, where exact is always 1 or more.

More Optiver Online Assessment questions

  • Chance a Die Game Balance Reaches ZeroOA · Seen Dec 2026
  • Chance a Hand of Cards Multiplies to More Than a ThresholdOA · Seen Dec 2026
  • Chance a Sum of Random Draws Has a Given Number of DigitsOA · Seen Dec 2026
  • Expected Profit of a Doubling Betting SystemOA · Seen Dec 2026
  • Expected Steps Until a Random Walk Gets Far From ZeroOA · Seen Dec 2026
  • Rolling Until One Face's Own Total Passes a ThresholdOA · Seen Dec 2026
  • Two Ranked Teams Meeting in a Random BracketOA · Seen Dec 2026
  • Overheat Prevention ControllerOA · Seen Nov 2026
  • Power Cell BankOA · Seen Nov 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026

Similar questions at other companies

  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
  • Sliding-Window Means with IEEE Special ValuesHeadlands Technologies · OAHeadlands Technologies interview questions
  • Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions
  • Polynomial CoefficientsShopify · OAShopify interview questions
  • Basic Calculator IITypeSafe AI · OA
  • Last Object to Fall Off the TableConfluent · OAConfluent interview questions
  • Last Object Exit TimeIBM · OAIBM interview questions
  • Count Prime Values in SubtreesVisa · OAVisa interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions

Optiver interview experiences

  • Optiver SWE Intern OA: CPU Temperature Simulation: 1 Experience
  • Optiver Trading Intern Market-Making Games: 1 Experience
  • Optiver Quant Trader Intern Technical Interview: 1 Experience
  • Optiver SWE Intern System Design Interview: 15 Experiences
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public double expectedDrawsUntilAllGreen(int blue, int green) {
        // Write your code here.
    }
}
Checking account…