Skip to content

Practice Check if Grid can be Cut into Sections

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3394
LeetCode Problem

Check if Grid can be Cut into Sections

Problem Statement

An n by n grid contains nonoverlapping rectangles [startX, startY, endX, endY], specified by bottom-left and top-right corners. Decide whether two horizontal cuts or two vertical cuts can divide the grid into three sections, each containing at least one whole rectangle, with every rectangle entirely in exactly one section. Cuts may lie along rectangle boundaries but cannot split rectangle interiors. Return whether such cuts exist.

Source: Check if Grid can be Cut into Sections on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, rectangles = [[1,0,5,2],[0,2,2,4],[3,2,5,3],[0,4,4,5]]
Output
true

# Example 2

Input
n = 4, rectangles = [[0,0,1,1],[2,0,3,4],[0,2,2,3],[3,0,4,3]]
Output
true

# Example 3

Input
n = 4, rectangles = [[0,2,2,4],[1,0,3,2],[2,2,3,4],[3,0,4,2],[3,2,4,4]]
Output
false

Constraints

3 <= n <= 10^9
3 <= rectangles.length <= 10^5
0 <= rectangles[i][0] < rectangles[i][2] <= n
0 <= rectangles[i][1] < rectangles[i][3] <= n
No two rectangles overlap.

Related LeetCode Problems

Practice more problems similar to Check if Grid can be Cut into Sections.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.