Count numbers with non repeating digits less than n

 Idea:

We can break the problem to two sub-problems:

  1. Count special ints with digits smaller than n.
  2. Count special ints with digits the same than n.

Sub-problem 1 is straightforward, we can just use basic combination.
Sub-problem 2 is harder, we can further divide it to two subsub-problems.

  1. Count special ints with digits the same than n. Use 345 as an example.
    1. Count special ints like 1xx and 2xx, where 45 is not a limitation here.
    2. Count special ints like 3xx, which is the same as special ints smaller than 45 and without digit 3.

Comments

Popular posts from this blog

Lowest common ancestor in a binary Tree

30. Substring with Concatenation of All Words

New start day 1 : 30/09/2020 (codeforces 71A) Way to long strings