Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Count Numbers with Unique Digits
Bookmark
Input
n = 3
n = 5
n = 8 (max)
n = 0 (edge)
Custom
n
=
3
n =
3
single digits
0–9
are all unique →
10
numbers
unique-digit numbers, counted by digit-length
10
≤1 digit
result =
10
count by digit-length: a leading digit has 9 choices, each next position one fewer
n =
3
single digits
0–9
are all unique →
10
numbers
unique-digit numbers, counted by digit-length
10
≤1 digit
result =
10
count by digit-length: a leading digit has 9 choices, each next position one fewer
n =
3
single digits
0–9
are all unique →
10
numbers
unique-digit numbers, counted by digit-length
10
≤1 digit
result =
10
add up: (≤1-digit) + (exactly 2-digit) + (exactly 3-digit) + …
n =
3
single digits
0–9
are all unique →
10
numbers
unique-digit numbers, counted by digit-length
10
≤1 digit
result =
10
base case →
result = 10
n =
3
unused digits =
9
building an 2-digit number, position by position
9
1–9
×
9
unused
=
81
unique-digit numbers, counted by digit-length
10
≤1 digit
result =
10
2-digit count =
81
n =
3
unused digits =
9
building an 2-digit number, position by position
9
1–9
×
9
unused
=
81
unique-digit numbers, counted by digit-length
10
≤1 digit
+
81
2 digits
result =
91
result +=
81
=
91
n =
3
unused digits =
8
building an 2-digit number, position by position
9
1–9
×
9
unused
=
81
unique-digit numbers, counted by digit-length
10
≤1 digit
+
81
2 digits
result =
91
one digit used up → next position has
8
choices
n =
3
unused digits =
8
building an 3-digit number, position by position
9
1–9
×
9
unused
×
8
unused
=
648
unique-digit numbers, counted by digit-length
10
≤1 digit
+
81
2 digits
result =
91
3-digit count =
648
n =
3
unused digits =
8
building an 3-digit number, position by position
9
1–9
×
9
unused
×
8
unused
=
648
unique-digit numbers, counted by digit-length
10
≤1 digit
+
81
2 digits
+
648
3 digits
result =
739
result +=
648
=
739
n =
3
unused digits =
7
building an 3-digit number, position by position
9
1–9
×
9
unused
×
8
unused
=
648
unique-digit numbers, counted by digit-length
10
≤1 digit
+
81
2 digits
+
648
3 digits
result =
739
one digit used up → next position has
7
choices
n =
3
10 + 81 + 648
unique-digit numbers, counted by digit-length
10
≤1 digit
+
81
2 digits
+
648
3 digits
result = 739
algo
master
.
io
Step:
Count every number x with 0 ≤ x < 10^3 whose digits are all distinct.
0 / 9
Input
n = 3
n = 5
n = 8 (max)
n = 0 (edge)
Custom
n
=
3
0 / 9
algo
master
.
io
Step:
Count every number x with 0 ≤ x < 10^3 whose digits are all distinct.