Count integers below 10^n that have no repeated digit

Quick Overview

Count how many integers from 0 up to 10^n, excluding 10^n itself, contain no repeated digit, for n from 0 to 8. It tests counting by number length with the multiplication principle and careful handling of leading zeros and the n = 0 case.

Count integers below 10^n that have no repeated digit

Company: Vmware

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given an integer `n`, return how many integers `x` with `0 <= x < 10^n` have unique digits, meaning no digit appears more than once in the decimal form of `x`. ### Function Signature ```python def count_numbers_with_unique_digits(n: int) -> int: ``` ### Rules - Numbers are written in ordinary decimal form with no leading zeros, so `7` is a one-digit number and `0` itself counts as a number with unique digits. - The range is half-open: `10^n` itself is not included. ### Constraints - `0 <= n <= 8` ### Examples ```text Input: n = 2 Output: 91 ``` The range `[0, 100)` holds 100 numbers. The only ones with a repeated digit are 11, 22, 33, 44, 55, 66, 77, 88 and 99, so the answer is 100 - 9 = 91. ```text Input: n = 0 Output: 1 ``` The range `[0, 1)` holds only the number 0, which has unique digits. ```text Input: n = 3 Output: 739 ``` Of the 900 three-digit numbers, 9 * 9 * 8 = 648 have distinct digits. Adding the 91 numbers below 100 from the first example gives 739.

Overview: Count how many integers from 0 up to 10^n, excluding 10^n itself, contain no repeated digit, for n from 0 to 8. It tests counting by number length with the multiplication principle and careful handling of leading zeros and the n = 0 case.

Vmware logo
Vmware
Nov 24, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given an integer n, return how many integers x with 0 <= x < 10^n have unique digits, meaning no digit appears more than once in the decimal form of x.

Function Signature

def count_numbers_with_unique_digits(n: int) -> int:

Rules

  • Numbers are written in ordinary decimal form with no leading zeros, so 7 is a one-digit number and 0 itself counts as a number with unique digits.
  • The range is half-open: 10^n itself is not included.

Constraints

  • 0 <= n <= 8

Examples

Input: n = 2
Output: 91

The range [0, 100) holds 100 numbers. The only ones with a repeated digit are 11, 22, 33, 44, 55, 66, 77, 88 and 99, so the answer is 100 - 9 = 91.

Input: n = 0
Output: 1

The range [0, 1) holds only the number 0, which has unique digits.

Input: n = 3
Output: 739

Of the 900 three-digit numbers, 9 * 9 * 8 = 648 have distinct digits. Adding the 91 numbers below 100 from the first example gives 739.