#3394
Check if Grid can be Cut into Sections
pupil · 590 · lc medium +29 · 68.3% accepted · 623 likes · top 75%
Description
You are given an integer n representing the size of an n x n grid (origin at the bottom-left), and a 2D array rectangles where rectangles[i] = [startx, starty, endx, endy] defines a non-overlapping rectangle.
- (startx, starty): the bottom-left corner.
- (endx, endy): the top-right corner.
Determine whether two horizontal or two vertical cuts can be made such that:
- Each of the three resulting sections contains at least one rectangle.
- Every rectangle belongs to exactly one section.
Return true if such cuts are possible; otherwise return false.
Code
1
2
3