FastPrepChance a Sum of Random Draws Has a Given Number of Digits
Problems/Chance a Sum of Random Draws Has a Given Number of Digits

Chance a Sum of Random Draws Has a Given Number of Digits

Optiver logoOptiver● MediumFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 post by a candidate for an Optiver full-time quant research OA lists several probability puzzles to practice with; we took one of them.

The puzzle draws four whole numbers at random, each anywhere from 10 to 99 and independent of the rest, and asks how likely their total is to be a three-digit number. No answer appears in the post.

What is ours: how many draws, the two ends of the range and the digit count are all inputs (up to 50 draws, values up to 1000, up to 9 digits; the report has 4 draws from 10 to 99 and 3 digits); a value may be drawn more than once; a total counts only when it has exactly that many digits, so a total of 10^digits or more is left out (in the reported case the total is at most 396, so only the lower end matters there); the checker takes a decimal answer whose gap from the true value is 10^-9 or smaller (absolute error). Example 1 matches the report; the limits and the other examples were picked by us.

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

You make count draws. Each draw picks one whole number from low, low + 1, ..., high (both ends included), every one of them with chance 1 / (high - low + 1), and independently of the other draws. So the same number may come up more than once.

Add up all the draws. Find the chance that this total, written in base 10, has exactly digits digits, meaning 10^(digits - 1) <= total <= 10^digits - 1. A total that is too large, with more than digits digits, does not count.

Function

probabilitySumHasDigits(count: int, low: int, high: int, digits: int) → double

Examples

Example 1

count = 4low = 10high = 99digits = 3return = 0.9909211248285322

The total is between 40 and 396, so three digits means a total of 100 or more. Take 10 off each draw: the four reduced values are 0 to 89 and the total is at most 99 only when they add up to 59 or less. No single value can pass 89 then, so there are C(63, 4) = 595,665 such outcomes out of 90^4 = 65,610,000. That leaves 1 - 595,665 / 65,610,000 = 1,444,763 / 1,458,000, about 0.9909211.

Example 2

count = 2low = 4high = 6digits = 1return = 0.3333333333333333

Two draws from 4, 5, 6 give 9 equally likely pairs. Totals 8, 9, 10, 11, 12 come from 1, 2, 3, 2, 1 pairs. Only 8 and 9 have one digit, which gives 3 / 9 = 1/3.

Example 3

count = 1low = 5high = 14digits = 1return = 0.5

One draw from the 10 values 5 to 14. The values 5 to 9 have one digit: 5 of 10, so 0.5.

Constraints

  • 1 <= count <= 50
  • 1 <= low <= high <= 1000
  • 1 <= digits <= 9
  • The checker allows an absolute error of 10^-9.

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

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
  • Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Jump Game with Prime-Step RuleUber · OAUber interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Unique Paths Through a GridPeopleStrong · OAPeopleStrong interview questions
  • Get Minimum OperationsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
  • Find Encrypted NumberAmazon · OA
  • Prime StringSnowflake · OASnowflake 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 probabilitySumHasDigits(int count, int low, int high, int digits) {
        // Write your code here.
    }
}
Checking account…