Nth Digit
MediumMathmath
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Write the positive integers one after another with no separators: 123456789101112131415....
Given n, return the n-th digit of this infinite sequence (1-indexed). The first digit is 1, the tenth digit is
the 1 of 10, and the eleventh is its 0.
Examples
Input: n = 3
Output: 3
The first nine digits are 1 through 9.
Input: n = 11
Output: 0
Digits 10 and 11 are the `1` and `0` of the number 10.
Constraints
- 1 <= n <= 2^31 - 1
- `n` is 1-indexed
- The sequence starts with the integer 1
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.