Skip to content

3394. Check if Grid can be Cut into Sections #1477

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine if we can make two horizontal or vertical cuts on an n x n grid such that the grid is divided into three sections, each containing at least one rectangle without any overlap. The approach involves checking both horizontal and vertical directions to see if such cuts are possible.

Approach

  1. Collect Intervals: For each rectangle, collect the x and y intervals.
  2. Merge Intervals: For each direction (x and y), merge overlapping intervals to form non-overlapping contiguous intervals.
  3. Check Validity: If the number of merged intervals in either direction is at least three, then it is possible to make the required cuts. This is because three or more non-overlapping intervals can…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Mar 25, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants