LeetCode 400, Medium. Topics: Math, Binary Search. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 29 parametrized pytest cases, and a playground notebook:
Problem
Given an integer n, return the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ....
Examples
Explanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … is a 0, which is part of the number 10.
Constraints
Follow up: Could you find the nth digit without using extra memory?
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026