← Back to challenges

Nth Digit of the Infinite Integers Sequence

PythonHardlanguage_fundamentalsloopsmathnumbers

Instructions

Consider the infinite sequence of integers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Find the nth digit in the string where all numbers are placed one after another without spaces. Digits counting starts from 1.

Examples

find_nth_digit(3) ➞ 3
# First digit of number 3

find_nth_digit(10) ➞ 1
# First digit of number 10

find_nth_digit(11) ➞ 0
# Second digit of number 10

find_nth_digit(15) ➞ 2
# Second digit of number 12

Notes

  • 1 <= n < 10^21
  • When you're done with this challenge, try an Airforce version by Mubashir.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.