Count Numbers with Unique Digits

MediumMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given an integer n, count the integers x with 0 <= x < 10^n whose decimal representation has no repeated digit. Numbers are written without leading zeros, and 0 itself counts as having unique digits. Return the count.

Examples

Input: n = 2
Output: 91
Of the 100 numbers 0 to 99, the nine numbers 11, 22, ..., 99 repeat a digit, leaving 91.
Input: n = 0
Output: 1
Only `x = 0` is in range.

Constraints

  • 0 <= n <= 8
  • The range considered is `0 <= x < 10^n`
  • Numbers have no leading zeros

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems