hardBacktrackingPure DSA~40 min
Tile a Rectangle with the Fewest Squares
A rectangular dashboard panel of size n x m must be covered with whole square tiles of integer side length, no overlaps and no gaps. Find the minimum number of square tiles needed.
Problem
Given a rectangle of width n and height m, return the minimum number of integer-sided squares that tile it exactly with no overlap and no empty space.
Input
Two integers n and m (rectangle dimensions).
Output
An integer: the minimum number of squares.
Constraints
- 1 <= n, m <= 13
Examples
Example 1
Input
n = 2, m = 3
Output
3
One 2x2 square plus two 1x1 squares.
Example 2
Input
n = 5, m = 8
Output
5
Five squares tile the 5x8 rectangle optimally.