← Back to challenges

Calculate How Many Numbers with Unique Digits

PythonHardmathnumbersloops

Instructions

The function is given an integer n. Count the numbers with unique digits in the range 0 <= num < pow(10, n).

Examples

nums_with_unique_digits(2) ➞ 91
# There are 100 numbers in total (from 0 to 99 inclusive).
# The following 9 numbers should not be counted:
# 11, 22, 33, 44, 55, 66, 77, 88, 99
# Thus 100 – 9 ➞ 91

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.