Reported August 2024
Salesforcemath

Count Numbers with Unique Digits

Reported by candidates from Salesforce's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Salesforce OA. Under 2s to a working solution.
Founder's read

Salesforce asked this in August 2024 and it's a combinatorial counting problem that trips up candidates who overthink it. You're counting how many numbers up to a given value have all unique digits. No repetition allowed. The trap is trying to iterate and check each number instead of recognizing this is a math and combinatorics play. StealthCoder can spot the pattern instantly if you blank on the formula during the live OA.

Pattern and pitfall

The key insight is that you're not iterating through numbers. You're counting valid permutations at each digit length. For a 1-digit number, you have 10 choices (0-9). For 2-digit, you pick the first digit from 1-9 (9 choices), then the second from remaining digits (9 choices), so 9*9. For 3-digit, it's 9*9*8. You cap out at 10 digits max since there are only 10 unique digits. The math: count all valid numbers of length 1, then 2, then 3, up to the length of your input number. For the exact input value, you need careful bounds checking. This is pure counting and permutation math, not dynamic programming or search.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Count Numbers with Unique Digits cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as count numbers with unique digits. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Salesforce's OA.

Salesforce reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Numbers with Unique Digits FAQ

Is this really just math, no DP?+

Yes. You're counting valid permutations at each digit length, not solving overlapping subproblems. The trick is recognizing the combinatorial structure: first digit has N choices, second has N-1, etc. No state needed.

What's the digit-by-digit breakdown for the input number itself?+

Once you count all numbers shorter than the input, you need to count valid numbers of the same length up to the input value. This requires iterating through digit positions and checking if you've already used that digit. It's the hard part.

Can I just iterate and check each number?+

No. For large inputs, this times out. The math approach is O(1) or O(number of digits). Brute force fails on the OA.

How do I handle leading zeros?+

Numbers don't have leading zeros. So the first digit of an N-digit number can only be 1-9. This affects your permutation count for each digit length.

Will this pattern come up again at other companies?+

Yes. This is a classic combinatorics + bounds problem. Google, Amazon, and others ask similar digit/permutation counting problems. The pattern is stable.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Salesforce.

OA at Salesforce?
Invisible during screen share
Get it