Skip to main content
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

  • 1 <= n <= 2^31 - 1
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

Tags

Last modified on September 7, 2026