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
Nth Digit Problem: Finding 11th DigitInput: n = 11Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12...Concatenated: 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2...123456789101234567891011Digits 1-9: positions 1-9 (9 digits)Number 10: positions 10-11 (digits '1', '0')Position 11 → second digit of 10 → '0'Output: 0
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
Asked in
Google 12 Apple 8 Microsoft 6
78.0K Views
Medium Frequency
~25 min Avg. Time
856 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen