Trains the technique from
LeetCode 400Nth DigitThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
Counting along the roll, character 47 falls inside the number 28 and is the second of its two characters.
Example 2
Characters 1 to 189 cover every number up to 99, so character 190 is the first character of 100.
Example 3
Character 1002 falls inside the number 370, on its last character.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def digit_at_spot(spot: int) -> int:public int digitAtSpot(int spot)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.