FastPrepExpected Profit of a Doubling Betting System
Problems/Expected Profit of a Doubling Betting System

Expected Profit of a Doubling Betting System

Optiver logoOptiver● HardFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One report, posted in 2026 about an Optiver online assessment for a full-time quantitative researcher role, lists probability practice questions; this problem is built on one of them.

In that question a player holding 31 dollars stakes 1 dollar per toss of a fair coin with even payouts, doubles the stake after every lost toss, and quits at the first winning toss or when the money is gone. It asks for the expected profit and gives no answer.

Our choices: the starting money, the number of won bets to stop at and the chance of winning a bet are inputs (up to 10^15 dollars and 10^15 wins; the report has 31 dollars, one win and a fair coin); after a win the next bet goes back to 1 dollar; play also stops when the next doubled bet is more than the money left, with no smaller last bet (for 31 dollars this is the same as running out of money); and the result is a decimal that may be off by up to 10^-9 (a relative error for answers larger than 1). The reported case is Example 1; we chose the other examples and all limits.

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

You start with bankroll dollars and play a betting game. Every bet succeeds with probability p, independent of every other bet. Bets pay even money: when a bet of s dollars succeeds you gain s dollars, and when it fails you give up those s dollars.

You follow a doubling system. Your first bet is 1 dollar. After a loss, your next bet is twice the bet you just lost. After a win, your next bet goes back to 1 dollar.

The game ends once you have won wins bets in total. It also ends when your next bet would be more than the money you have left: you never bet money you do not have, and you never bet less than the system says. Any money left at that point stays with you.

Your profit is the money you hold when you stop minus bankroll. Return the expected value of your profit. An answer counts as correct if it is off by at most 10^-9 when the correct value is from -1 to 1, and by at most 10^-9 times the size of the correct value otherwise.

Function

expectedProfit(bankroll: long, wins: long, p: double) → double

Examples

Example 1

bankroll = 31wins = 1p = 0.5return = 0.0

The bets 1, 2, 4, 8 and 16 add up to exactly 31. If one of them wins, you end 1 ahead; that happens with chance 31/32. If all five lose (chance 1/32), you are down 31 with nothing left. The expected profit is (31/32) · 1 - (1/32) · 31 = 0.

Example 2

bankroll = 3wins = 2p = 0.6return = 0.6624

Each round starts with 3 or 4 dollars, enough for the bets 1 and 2 but not a third bet of 4. A round fails when both bets lose, chance 0.4 · 0.4 = 0.16, and that costs 3. Failing the first round gives -3 (chance 0.16); winning it and failing the second gives 1 - 3 = -2 (chance 0.84 · 0.16 = 0.1344); winning both gives +2 (chance 0.84 · 0.84 = 0.7056). The expected profit is -0.48 - 0.2688 + 1.4112 = 0.6624.

Example 3

bankroll = 2wins = 3p = 0.4return = -0.48864

With 2 dollars you can bet 1, but after a loss you cannot cover a bet of 2, so the first round is a single bet. After one win you have 3 dollars, and the rounds after that can afford bets of 1 and 2. Losing the first bet gives -1 (chance 0.6). Winning it and then losing a two-bet round gives 1 - 3 = -2 (chance 0.4 · 0.36 = 0.144). Winning two rounds and losing the third gives 2 - 3 = -1 (chance 0.4 · 0.64 · 0.36 = 0.09216). Winning all three gives +3 (chance 0.4 · 0.64 · 0.64 = 0.16384). The expected profit is -0.48864.

Constraints

  • 1 <= bankroll <= 10^15
  • 1 <= wins <= 10^15
  • 0 <= p <= 1
  • Your answer is accepted when it differs from the correct value by at most 10^-9 · max(1, |correct value|).

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 Draws to Remove All Green CountersOA · 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

  • Bootstrap Decision Tree ClassifierPinterest · OAPinterest interview questions
  • Predict Taxi Driver ClassesBoston Consulting Group · OABoston Consulting Group interview questions
  • Arithmetic Triplets After QueriesCapital One · OACapital One interview questions
  • Bring Servers DownAmazon · OA
  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Last Object Exit TimeIBM · OAIBM interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Find Total CostJP Morgan Chase · OAJP Morgan Chase 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 expectedProfit(long bankroll, long wins, double p) {
        // Write your code here.
    }
}
Checking account…