Ctrl K

Square Tile Floor

Hard
A rectangular floor of height × width cells has to be covered with square tiles. Each tile's side is a whole number of cells; tiles may be of any sizes, including different ones. Tiles must not overlap, stick out past the edge of the floor, or leave any gaps. Return the smallest number of tiles that covers the whole floor.
Example 1
height=3, width=2 → 3

One 2×2 tile and two 1×1 tiles below it.

Example 2
height=4, width=6 → 3

A 4×4 tile with two 2×2 tiles stacked next to it.

Example 3
height=5, width=5 → 1

The floor is square, so a single 5×5 tile does it.

Constraints
  • 1 ≤ height, width ≤ 13
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsComplete the Sudoku HardPeaceful Queens HardPeaceful Queens HardEvery Way to Space the Words HardWords Hidden in a Letter Grid Hard
loading Python…
Input
height=3, width=2
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 60 tests on the server, hidden ones included.