Even and Odd Digit Pattern Probability
Updated
Problem statement
Let n be the length of pattern. A whole number with exactly n digits is picked uniformly at random, so every number from 10n-1 to 10n - 1 is equally likely (for n = 1, the numbers 1 to 9). The first digit is never 0.
Character i of pattern describes digit i of the number, counting from the left:
'E': the digit must be even (0,2,4,6or8).'O': the digit must be odd.'*': the digit can be anything.
Return the probability that the picked number fits the whole pattern. Answers within 10-6 of the correct value are accepted.
Function
digitParityProbability(pattern: String) → doubleExamples
Example 1
pattern = "EO*"return = 0.2222222222222222Three-digit numbers run from 100 to 999, so there are 900 of them. The first digit must be 2, 4, 6 or 8 (4 ways), the second must be odd (5 ways) and the third can be anything (10 ways). That is 4 * 5 * 10 = 200 numbers, and 200 / 900 = 2/9.
Example 2
pattern = "O"return = 0.5555555555555556The one-digit numbers are 1 to 9. Five of them are odd, so the answer is 5/9. It is not 1/2, because 0 is not a choice for the first digit.
Example 3
pattern = "**E*"return = 0.5Only the third digit is fixed, and it can be any of 0 to 9, half of them even. The answer is 1/2.
Constraints
1 <= pattern.length <= 9patterncontains only the characters'E','O'and'*'.
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Good SubsequencesNutanix · OANutanix interview questions
- Unique Digit Permutations Without Leading ZeroMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Revolver: Will the Next Shot Fire?Tower Research Capital · PHONE SCREEN
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Expected Fake-Name CollisionsMercor · PHONE SCREENMercor interview questions
Interview reports that mention this question
Jane Street interview experiences
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
- Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
- Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)
- Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)