Numbers At Most N Given Digit Set
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 neededProblem
You are given a sorted array digits of distinct single-character strings, each one of '1' to '9'. You can build positive integers by writing digits from this set, reusing any digit as many times as you like (for example, ["1","3"] builds 1, 13, 311, ...).
Return how many positive integers you can build that are **less than or equal to** n.
n can be as large as 10^9, so count by digit positions instead of generating numbers.
Examples
Constraints
- 1 <= digits.length <= 9
- digits[i].length == 1 and digits[i] is one of "1" to "9"
- All values in digits are distinct and sorted ascending
- 1 <= n <= 10^9
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.