Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created March 25, 2025 21:36
Show Gist options
  • Save Ifihan/aa4ba4db9381edac9a7d756e4b04b08e to your computer and use it in GitHub Desktop.
Save Ifihan/aa4ba4db9381edac9a7d756e4b04b08e to your computer and use it in GitHub Desktop.
Check if Grid can be Cut into Sections

Question

Approach

To solve this, I grouped the rectangles by sorting them based on their x or y coordinates. Then, I scanned through the sorted list to find points where I could split them into three non-overlapping groups—each with at least one rectangle and no rectangle spanning across the cut. I checked both horizontal and vertical directions, and if either allowed such a split, I returned True; if not, I returned False.

That didn't pass all the cases which is weird and didn't find why it was like that. So I checked the editiorial and saw my mistaskes.

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment