Ctrl K

Numbers That Reuse a Digit

Hard
You are given an integer limit. Count how many numbers from 1 to limit inclusive use at least one digit two or more times in their decimal form. The repeats do not have to be adjacent: 101 reuses the digit 1. Checking every number up to limit will not do — there can be a billion of them.
Example 1
limit=30 → 2

Up to 30, only 11 and 22 repeat a digit.

Example 2
limit=9 → 0

A one-digit number cannot repeat a digit.

Example 3
limit=111 → 13

The nine numbers 11, 22, …, 99, plus four more: 100, 101, 110 and 111.

Constraints
  • 1 ≤ limit ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Many Ones Are Written HardTasters and the Spoiled Cask HardTwo Groups With the Same Average HardPrototype Drop Tests HardNumbers From Working Keys Hard
loading Python…
Input
limit=30
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 58 tests on the server, hidden ones included.