Calculate How Many Numbers with Unique Digits

Published by Evgeny SH in

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

Watch a quick demo on how Edabit works.