Trains the technique from
LeetCode 279Perfect 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 courtyard crew paves a strip whose surface measures exactly area square metres. The
supplier stocks square slabs in every whole-metre side length: 1 by 1, 2 by 2, 3 by 3 and so
on, in unlimited quantity, and a slab of side s covers s * s square metres.
The crew lays slabs so that the covered surface adds up to area with nothing left over and
nothing overlapping. Only the areas matter here, not how the slabs sit next to each other,
and the same side length may be used as often as needed.
Given area, return the smallest number of slabs whose areas add up to exactly area.
Example 1
Three slabs of side 2 and one of side 4 cover 4 + 4 + 4 + 16, which is 28 square metres with four slabs.
Example 2
Two slabs of side 3 cover 9 + 9, which is exactly 18 square metres.
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_tiles(area: int) -> int:public int fewestSquareTiles(int area)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.