Numbers With Repeated Digits

Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.

Example 1
Inputn = 20
Output1
The only positive number less than or equal to 20 with at least one repeated digit is 11.
Example 2
Inputn = 100
Output10
The positive numbers less than or equal to 100 with at least one repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.

Constraints

  • 1 <= n <= 10^9

Asked at 2 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate