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

LeetCode 3Sum

New start Day 2 (1/10/2020) codeforces 492B Vanya and Lantern

Heap (min)