Count Distinct Integers After Removing Zeros

You are given a positive integer n.

For every integer x from 1 to n, write down the integer obtained by removing all zeros from the decimal representation of x.

Return an integer denoting the number of distinct integers written down.

Example 1
Inputn = 10
Output9
The integers written down are 1, 2, 3, 4, 5, 6, 7, 8, 9, and 1, so there are 9 distinct integers.
Example 2
Inputn = 3
Output3
The integers written down are 1, 2, and 3, so there are 3 distinct integers.

Constraints

  • 1 <= n <= 10^15

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate