Nth Digit
Real-world version: Digit At A Spot On The Numbering RollThe statement here is our own: the same inputs, outputs and technique.
A numbering machine prints a continuous paper roll. It prints 1, then 2, then 3, and so on without end, laying the characters of each number down one after another with nothing at all between numbers. The roll therefore begins 123456789101112..., so the tenth and eleventh characters are the 1 and the 0 of the number ten.
Characters are counted from 1 at the start of the roll. Given spot, return the single digit printed at that character position, as an integer from 0 to 9.
spot may run into the billions, so the roll cannot be printed out and indexed: your work must not scale with spot itself.
Examples
Example 1
- Input
- spot = 47
- Output
- 8
Counting along the roll, character 47 falls inside the number 28 and is the second of its two characters.
Example 2
- Input
- spot = 190
- Output
- 1
Characters 1 to 189 cover every number up to 99, so character 190 is the first character of 100.
Example 3
- Input
- spot = 1002
- Output
- 0
Character 1002 falls inside the number 370, on its last character.
Constraints
- 1 <= spot <= 2^31 - 1
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def digit_at_spot(spot: int) -> int:public int digitAtSpot(int spot)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 21 test cases: 21 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's