Tiling a Rectangle with the Fewest Squares

Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.

Example 1
Inputn = 2, m = 3
Output3
Three squares are necessary: two 1x1 squares and one 2x2 square.
Example 2
Inputn = 5, m = 8
Output5
The 5 x 8 rectangle can be tiled using a minimum of 5 integer-sided squares.

Constraints

  • 1 <= n, m <= 13

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate