Nth Digit

MediumMath

Description

Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... The sequence concatenates all positive integers.

Examples

Input:n = 11
Output:0
Explanation:

Sequence is 123456789101112..., 11th digit is 0 from 10.

Input:n = 3
Output:3
Explanation:

The sequence is 123456789101112... The first 9 digits are single-digit numbers 1-9. The 3rd digit is 3.

Input:n = 15
Output:2
Explanation:

The sequence is 123456789101112131415... Single digits 1-9 take positions 1-9, then 10 takes positions 10-11, 11 takes positions 12-13, 12 takes positions 14-15. The 15th digit is 2 from the number 12.

Constraints

  • 1 ≤ n ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.