Nth Digit - Problem
Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].
The sequence is formed by concatenating all positive integers: 123456789101112131415...
Note: The digit indexing starts from 1 (1-indexed).
Input & Output
Example 1 — Finding 11th Digit
$
Input:
n = 11
›
Output:
0
💡 Note:
Sequence: 123456789101112... The 11th digit is the second digit of 10, which is 0
Example 2 — Single Digit
$
Input:
n = 3
›
Output:
3
💡 Note:
Sequence: 123456789... The 3rd digit is simply 3
Example 3 — Two-Digit Range
$
Input:
n = 15
›
Output:
2
💡 Note:
Sequence: 123456789101112131415... Position 15 is the first digit of 12, which is 1. Wait, let me recalculate: positions 1-9 are digits 1-9, positions 10-11 are '1','0' from 10, positions 12-13 are '1','1' from 11, positions 14-15 are '1','2' from 12. So 15th digit is '2'
Constraints
- 1 ≤ n ≤ 2³¹ - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given n = 11
2
Sequence
Concatenate integers: 123456789101112...
3
Output
Find 11th digit which is 0
Key Takeaway
🎯 Key Insight: Use mathematical patterns of digit contributions to avoid counting one by one
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code