FastPrepCount the 2s From 1 to n
Problems/Count the 2s From 1 to n

Count the 2s From 1 to n

Jane Street logoJane Street● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in one Jane Street trading desk operations report from the U.S., posted in 2019. The process it describes had a take-home test, three phone interviews and a final interview in the office. Its counting teaser covers the digit 2 across the range 1 to one million. The report does not say which round asked it.

Our function takes any upper limit n. The limit on n and the second and third examples are ours.

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

You write down every whole number from 1 to n in decimal, without leading zeros.

Return how many times the digit 2 appears in total.

Function

countDigitTwo(n: int) → int

Examples

Example 1

n = 1000000return = 600000

Look at the numbers 1 to 999999 as six-digit strings with leading zeros. Each of the six places shows a 2 in exactly one out of every ten numbers, so each place holds 100000 twos, 600000 in all. Leading zeros never add a 2, and 1000000 itself has none.

Example 2

n = 25return = 9

The numbers 2, 12, 20, 21, 23, 24 and 25 each have one 2, and 22 has two, for 9 in total.

Example 3

n = 1return = 0

Only the number 1 is written, and it has no 2.

Constraints

  • 1 <= n <= 109

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

  • Election District Budget Allocation AnalysisIMC Trading · PHONE SCREENIMC Trading interview questions
  • Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
  • 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
  • Best Single Reroll for Five DiceSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
  • Extra Coin Win ProbabilityMicrosoft · PHONE SCREENMicrosoft interview questions
  • Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions

Interview reports that mention this question

  • Jane Street TDO Earlier US Finals: 19 Experiences (Part 7 of 10)

Jane Street interview experiences

  • Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
  • 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)
All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public int countDigitTwo(int n) {
      // Write your code here.
    }
}
Checking account…