HARDasked at 1 company

Numbers At Most N Given Digit Set

A hard-tier problem at 43% community acceptance, tagged with Array, Math, String. Reported in interviews at TikTok and 0 others.

Founder's read

You've got a digit set and an upper bound N. Build all numbers you can form that don't exceed N. TikTok has asked this one. It looks straightforward until you realize the greedy approach breaks on numbers where you can't greedily step down in the digit set without losing valid smaller options. Most candidates either brute-force (slow) or miss the combinatorial cases entirely. The acceptance rate sits around 43 percent for a reason. If this lands in your live OA and you're stuck on the case logic, StealthCoder runs silently and surfaces the working solution.

Companies asking
1
Difficulty
HARD
Acceptance
43%

Companies that ask "Numbers At Most N Given Digit Set"

If this hits your live OA

Numbers At Most N Given Digit Set 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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The trick is building numbers by position, not by iterating 1 to N. For each digit position, you count how many valid numbers exist if you fill the remaining slots with the smallest digit from your set. The pattern: if your current digit matches N's digit at that position, move to the next position. If you place a smaller digit, all remaining positions can use any digit from your set, so add the combinatorial count. Once you place a digit smaller than N's at any position, you're free to fill the rest with the largest allowed digit. String manipulation and careful state tracking matter more than algorithmic complexity here. This is a DP problem disguised as a counting problem. When you're live and the logic tangles, StealthCoder eliminates the guesswork.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Numbers At Most N Given Digit Set recycles across companies for a reason. It's hard-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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Numbers At Most N Given Digit Set interview FAQ

Why doesn't greedy digit selection work here?+

Greedy picking the largest digit at each position doesn't guarantee you form valid numbers under N. You need to count all valid combinations, including those where you pick smaller digits early to unlock more options later. This forces a DP or digit-DP approach.

Is this still asked after the drop in FAANG interview volume?+

TikTok remains active on this problem. It's less frequent than two years ago, but shows up in their medium to hard rotation. If you're targeting TikTok specifically, this is worth a dry run or two.

What's the hardest part candidates miss?+

The combinatorial counting of 'free digits' after you place a digit smaller than N's digit at a position. Many build the first valid number and stop. You need to count all permutations of the remaining positions filled with your digit set.

How does this relate to digit DP?+

This is a classic digit DP problem. You process N digit by digit, tracking whether you're still bounded by N's digits or free to pick any digit from your set. The DP state is position and whether you're tight to N's constraint.

Can you solve this without string manipulation?+

You need to handle N as individual digits, so string or array conversion is necessary. The math involves factorials and permutations, but the interface is inherently string-based.

Want the actual problem statement? View "Numbers At Most N Given Digit Set" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.