Loading Now

beautifulNumbers

As we knew, the number is no limit. Each number is unique but in another side they have the same level of beautiful.

A non negative integer is beautiful if it consists of only one digit repeated one or more times.

Example:The following numbers are beautiful: 0, 1, 22, 666 and 99999.

The following numbers are not beautiful: 212, 1110, 6969 and 987654321.

So your question is : Find the number of numbers from 0 to n (inclusive) that are beautiful.

Example:

  • For n = 16, the output should be beautifulNumbers(n) = 11.

    The beautiful Numbers from 0 to 16 are : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11.

Input/Output:

  • [Execution time limit] 0.1s in C++, 1s in Java, C#, Python, GO and Js..
  • [Input] long
    0 <= n <= 1018
  • [Output] integer
    The number of beautiful number between 0 and n(inclusive).

Post Comment

Contact