MEDIUMasked at 1 company

Count Good Numbers

A medium-tier problem at 57% community acceptance, tagged with Math, Recursion. Reported in interviews at Amazon and 0 others.

Founder's read

Count Good Numbers is a medium-difficulty problem that's deceptively simple on the surface. Amazon has asked this one, and the acceptance rate sits at 56%, which means half the candidates walk away confused. You'll see a number with even and odd positions, and you need to count how many valid numbers exist where even positions have digits 0-4 and odd positions have digits 0-7. The trick isn't the counting logic. It's realizing this is a combinatorics problem that explodes into huge numbers, and your brute-force recursion will time out or overflow without the right optimization. If you blank on the pattern during your live assessment, StealthCoder surfaces a working solution in seconds.

Companies asking
1
Difficulty
MEDIUM
Acceptance
57%

Companies that ask "Count Good Numbers"

If this hits your live OA

Count Good Numbers 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 by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The instinct is to recurse and count: valid numbers at position 0, then position 1, then position 2, and so on. That works for small inputs. But the number of possibilities grows exponentially. Position i at an even index has 5 choices (0-4), odd index has 8 choices (0-7). You're computing 5^(even_count) * 8^(odd_count). Most candidates either implement naive recursion that's too slow or forget to modulo the result by 10^9+7. The real solution is recognizing this as a pure math problem: count even and odd positions in the input, compute the powers using fast exponentiation with modulo, and multiply. Recursion here is a red herring. The topics list includes both Math and Recursion, but Math is where the actual solution lives. StealthCoder cuts through this misdirection and shows you the modular exponentiation pattern that makes it instant.

Pattern tags

The honest play

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

Count Good Numbers 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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Good Numbers interview FAQ

Is Count Good Numbers actually a recursion problem?+

It's labeled as one, but the optimal solution is pure combinatorics and modular exponentiation. Recursion is the wrong tool. You count even and odd positions, compute 5^even_positions * 8^odd_positions mod 10^9+7, and return the result. Understanding the difference saves you from timeout.

What's the biggest pitfall on this problem?+

Forgetting to apply modulo 10^9+7 when computing powers. Your intermediate results balloon into numbers Python can handle but your logic gets messy. Also, computing powers naively with loops or repeated multiplication is slow. Use built-in fast exponentiation (pow with three arguments) or implement it correctly.

Why is the acceptance rate only 56% if it's medium difficulty?+

The misdirection. Candidates see 'Recursion' in the topics and overcomplicate it. They also miss the modulo requirement or compute powers inefficiently. The problem rewards recognizing it as a pure math pattern, not a recursive tree exploration. That insight isn't obvious without seeing similar problems.

How do I know if my solution is efficient enough?+

Your code should compute the answer in a single pass with logarithmic exponentiation (O(log n) per power call). If you're iterating through positions and doing work at each step, you're overthinking. Count even and odd positions once, compute two powers, multiply, done. No loops over the digit string itself.

Does Amazon ask this problem to filter out weak candidates?+

Likely. It tests whether you recognize a combinatorics problem versus a recursion problem, and whether you know modular arithmetic. These are foundational skills. The 56% acceptance rate suggests most candidates miss the pattern or implement it sloppily. It's a screening question, not a deep coding challenge.

Want the actual problem statement? View "Count Good Numbers" 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.