Count Numbers with Unique Digits
A medium-tier problem at 54% community acceptance, tagged with Math, Dynamic Programming, Backtracking. Reported in interviews at J.P. Morgan and 0 others.
Count Numbers with Unique Digits shows up in J.P. Morgan screens and stumps candidates who treat it as a simple math problem. The question asks: how many numbers from 0 to 10^n have all distinct digits. It sounds straightforward until you realize brute force checking every number times n fails at scale. You need to see that this is a combinatorial permutation problem, not iteration. Most candidates either time out or miss the mathematical insight entirely. If this problem hits your live OA and you blank on the counting logic, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Count Numbers with Unique Digits"
Count Numbers with Unique Digits is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is recognizing that unique-digit constraints follow permutation rules, not loop patterns. For n-digit numbers with all different digits, you have 9 choices for the first digit (1-9), then 9 for the second (0-9 minus the first), then 8 for the third, and so on. The pattern caps out at n=10 because you run out of distinct digits after that. Backtracking or Dynamic Programming can solve it, but most fast solutions just compute the sum of these permutations directly. The pitfall: trying to iterate and check each number individually, or not seeing that the answer for n=10 is the same as n=11 and beyond. StealthCoder is the hedge if you freeze on the combinatorial structure during the assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Numbers with Unique Digits recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Numbers with Unique Digits interview FAQ
Is this really a Medium problem?+
The acceptance rate sits at 54%, which means slightly more than half pass it. It's genuinely Medium in difficulty. The math insight is not obvious, and the implementation can break if you don't handle the permutation logic correctly or the n=10 edge case.
Do I need Backtracking, Dynamic Programming, or Math to solve it?+
You need at least one. Most candidates use Math (permutation sum) because it's fastest. Backtracking and DP both work but are slower. The input lists all three topics, meaning all three are valid approaches. Pick whichever you're most comfortable reasoning through under time pressure.
Why does J.P. Morgan ask this?+
Financial firms like J.P. Morgan test combinatorics and pattern recognition under pressure. This problem checks if you can switch from algorithmic thinking to mathematical reasoning. It's not about coding speed; it's about seeing the structure.
What's the hardest part of this problem?+
The hardest part is not overthinking it. Most candidates try to build a DP table or backtrack through candidates. Once you see that you're just summing permutations (9*9*8*7*...), the code becomes four lines. The insight is the bottleneck, not the code.
Does this problem appear in other companies' screens?+
Reports show J.P. Morgan as the primary known asker. It appears in screens less frequently than typical LeetCode favorites, but when it does, it's a strong signal that the company values discrete math and combinatorial thinking over raw data structure knowledge.
Want the actual problem statement? View "Count Numbers with Unique Digits" on LeetCode →