Trains the technique from
LeetCode 1240Tiling a Rectangle with the Fewest SquaresThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A glazier has to cover a rectangular panel that measures width units across and height units up, using square patches of glass.
Every patch has an integer side length of at least one unit and is laid with its sides parallel to the panel's sides. Patches may be of different sizes, they may not overlap each other, and no patch may stick out past the panel's edge. Together the patches must cover every point of the panel.
Return the smallest number of patches that covers the panel.
Example 1
Five patches cover the panel: a 4 by 4 patch filling the bottom four rows, then a 3 by 3 patch in the left three columns of the remaining band, and three 1 by 1 patches stacked in the last column of that band.
Example 2
Four patches cover the panel: two 2 by 2 patches filling the bottom four rows, then two 1 by 1 patches side by side in the top row.
Example 3
The panel is already square, so one 13 by 13 patch covers it.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def fewest_square_patches(width: int, height: int) -> int:public int fewestSquarePatches(int width, int height)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.