Reported September 2024
Microsoftdynamic programming

Count Good Arrays

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

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

Microsoft's Count Good Arrays hit your inbox in September 2024, and you've got 36-48 hours to get ready. This is a combinatorics problem dressed up as a counting challenge. The trap: candidates overthink the constraints and miss the mathematical structure underneath. The trick: modular arithmetic and careful enumeration of valid states. StealthCoder sits invisible during the assessment, ready to surface the recurrence relation if you blank on the spot.

Pattern and pitfall

Count Good Arrays is asking you to count integer sequences that satisfy specific constraints, typically involving divisibility or modular conditions across consecutive elements. The pattern is dynamic programming with math baked in. You'll define a state (position, last value or last remainder), compute valid transitions, and sum up valid paths to the end. The gotcha: the moduli and divisibility rules interact in ways that break naive DP. You need to track both the element value and its remainder properties. The common miss: forgetting to apply the modulo 10^9+7 at every step, or misunderstanding which elements must divide which. StealthCoder handles the state transitions and mod arithmetic so you don't burn time debugging off-by-one errors in the live OA.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Count Good Arrays 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Microsoft reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Good Arrays FAQ

Is this really just DP, or is there a math formula?+

It's DP with math. You'll iterate through positions and valid values, track remainders, and sum paths. No closed-form formula. The math part is understanding divisibility chains and applying modular arithmetic correctly at each step.

What does 'good' mean in the problem?+

Good arrays satisfy constraints like 'element at index i is divisible by i' or 'consecutive elements satisfy a modular relation.' The exact rule matters. Read the constraint carefully and encode it as a transition check in your DP.

How do I avoid the mod 10^9+7 trap?+

Apply it every time you add or multiply. Don't wait until the end. Initialize a constant MOD = 10^9+7. Every DP update should be dp[next_state] = (dp[next_state] + dp[current_state]) % MOD.

Should I build the entire DP table upfront or iterate smartly?+

Iterate through positions, and for each position, iterate through valid values or remainders. Prune states that violate constraints early. This keeps memory and time reasonable. Two-state or rolling-array optimizations often work.

How hard is this for a 45-minute OA?+

Medium to hard. The constraint reading takes 5-10 minutes. DP formulation is 10-15 minutes if you've seen combinatorics DP before. Implementation and debugging, 15-20 minutes. Doable if you stay calm and test a small example first.

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

OA at Microsoft?
Invisible during screen share
Get it