Min Num Tiles
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Microsoft's Min Num Tiles hit the assessment circuit in August 2024, and it's a classic dynamic programming trap disguised as a greedy problem. You're given some kind of tiling or covering scenario where you need to minimize the number of tiles used. The trick is that greedy doesn't work here. You'll need to build up a table of minimum costs and realize that some tile sizes or placements block better solutions downstream. StealthCoder can spot the DP substructure in real time if you blank on the state definition.
Pattern and pitfall
The core pattern is dynamic programming. You're either tiling a 1D line, a 2D grid, or covering a word/string with a fixed set of tile sizes. The mistake most candidates make is trying to greedily pick the largest tile that fits. That fails because leaving a tiny gap might force you to use three small tiles later when one medium tile would've worked. The solution requires defining state as dp[position] = minimum tiles to cover up to that position, then iterating through valid tile sizes and updating. Edge cases: can you reuse tiles, what if no solution exists, how do you handle boundaries. If you freeze up during the assessment, StealthCoder will pattern-match this as DP and walk you through state transitions.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Min Num Tiles 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as perfect squares. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Num Tiles FAQ
Is this really a DP problem and not greedy?+
Yes. Greedy fails because the locally optimal choice (largest tile) creates subproblems that require more tiles overall. DP explores all valid placements and memoizes the minimum cost at each step.
What should my state be?+
dp[i] = minimum number of tiles to cover position 0 to i. For each position, try every valid tile size that fits and take the minimum result.
How do I know what tiles are available?+
The problem will give you a list or set of valid tile sizes. Some variants let you use tiles from 1 to some max value. Read the constraints carefully.
What's a common edge case?+
A position that no single tile can cover alone, or a remainder that doesn't match any tile size. Handle by checking if a solution exists before returning.
Can I solve this in 15 minutes cold?+
If you recognize the DP pattern, yes. If you try greedy first and it fails, you'll lose time. Spot the counterexample early and pivot to DP immediately.