All problems
Nth Digit of the Sequence
Problem
Return the n-th digit (1-indexed) of the infinite sequence formed by writing the positive integers in order: 123456789101112 and so on.
Skip whole blocks of numbers by their digit length, then locate the exact number and digit position. Assume n >= 1.
Hint
The block of d-digit numbers starts at 10 to the d minus 1 and holds 9 times that many digits.
Test cases
case 1
in: [1]
expected: 1
case 2
in: [10]
expected: 1
case 3
in: [11]
expected: 0
case 4
in: [12]
expected: 1
case 5
in: [1000]
expected: 3
Starter codePython
def nth_digit(n):
# Your code here
pass5 test cases · run your code against them in the editor