FunctionRacerProblemsRace

Tiles That Make a Rectangle

HardHash mapsPython, JavaScript, TypeScript, Java, C++

Each tile is [x1, y1, x2, y2]: its bottom left corner (x1, y1) and its top right corner (x2, y2), with sides parallel to the axes.

Return True if the tiles together cover a rectangle exactly, with no gap and no two tiles overlapping, otherwise False. Tiles may touch along their edges.

Example 1

tiles [[0,0,2,1],[2,0,3,2],[0,1,2,2]]
returns true

Two flat tiles stacked on the left and one upright tile on the right fill a rectangle 3 wide and 2 high.

Example 2

tiles [[0,0,1,1],[1,1,2,2]]
returns false

The two squares touch only at a corner, so half of the square around them stays empty.

Example 3

tiles [[0,0,2,1],[1,0,3,1]]
returns false

The tiles overlap between x = 1 and x = 2.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems