You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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] is in the form [startx, starty, endx, endy], representing 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.
Rectangles do not overlap.
Your task is to determine if it is possible to make either two horizontal or two vertical cuts on the grid such that:
Each of the three resulting sections formed by the cuts contains at least one rectangle.
Every rectangle belongs to exactly one section.
Return true if such cuts can be made; otherwise, return false.
📢 Feel free to contribute by improving the solution or adding more test cases! 🚀
---
This **README.md** file includes:
✅ **Clear problem statement**
✅ **Examples with input/output and diagrams**
✅ **Constraints and approach hints**
✅ **Time complexity analysis**
Let me know if you need any modifications! 😊🔥
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
🟩 3394. Check if Grid can be Cut into Sections
Medium | Grid | Geometry | Sorting
📝 Problem Statement
You are given an integer
n
representing the dimensions of ann x n
grid, with the origin at the bottom-left corner of the grid.You are also given a 2D array of coordinates
rectangles
, whererectangles[i]
is in the form[startx, starty, endx, endy]
, representing 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:
Return
true
if such cuts can be made; otherwise, returnfalse
.🔹 Example 1
Input:
Output:
true
Explanation:
We can make horizontal cuts at
y = 2
andy = 4
.Hence, output is
true
.🔹 Example 2
Input:
Output:
true
Explanation:
We can make vertical cuts at
x = 2
andx = 3
.🔹 Example 3
Input:
Output:
false
Explanation:
We cannot make two horizontal or two vertical cuts that satisfy the conditions. Hence, output is
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.
💡 Approach & Hints
🔹 If a valid set of two horizontal or two vertical cuts exists, return
true
, else returnfalse
.⏳ Time Complexity Analysis
m
is the number of rectangles.m ≤ 10^5
).✍ Author
👤 Antim PAl
📧 [email protected]
🌐 [GitHub Profile]
📢 Feel free to contribute by improving the solution or adding more test cases! 🚀
Beta Was this translation helpful? Give feedback.
All reactions