You are given an integer n
representing the dimensions of an n x n
grid, with the origin at the bottom-left corner of the grid. You are also given a 2D array of coordinates rectangles
, where rectangles[i] = [startx, starty, endx, endy]
represents a rectangle on the grid. Each rectangle is defined as follows:
(startx, starty)
: The bottom-left corner of the rectangle.(endx, endy)
: The top-right corner of the rectangle.Your task is to determine if it is possible to make either two horizontal or two vertical cuts on the grid such that:
true
if such cuts can be made.false
otherwise.n = 5
rectangles = [[1,0,5,2],[0,2,2,4],[3,2,5,3],[0,4,4,5]]
We can make horizontal cuts at y = 2
and y = 4
, forming three sections:
y = 2
(contains R1
)y = 2
and y = 4
(contains R2
and R3
)y = 4
(contains R4
)Since all conditions are satisfied, output is true
.
Rectangles do not overlap.
https://leetcode.com/problems/check-if-grid-can-be-cut-into-sections/description/
Loading component...
Loading component...