Skip to content

Commit b7fae2a

Browse files
committed
Mar 25
1 parent 8c78a00 commit b7fae2a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Solution:
2+
def __calculate_boundaries(self, rectangles: list[list[int]], dim: int) -> list[tuple[int, int]]:
3+
boundaries = [(rectangle[dim], rectangle[dim+2]) for rectangle in rectangles]
4+
boundaries.sort()
5+
return boundaries
6+
7+
def __line_sweep(self, lines: list[tuple[int, int]]) -> bool:
8+
n_lines = 0
9+
last = lines[0][1]
10+
for start, end in lines:
11+
if start >= last:
12+
n_lines += 1
13+
if n_lines == 2:
14+
return True
15+
last = max(last, end)
16+
return False
17+
18+
def checkValidCuts(self, _: int, rectangles: list[list[int]]) -> bool:
19+
h_lines = self.__calculate_boundaries(rectangles, 1)
20+
v_lines = self.__calculate_boundaries(rectangles, 0)
21+
return self.__line_sweep(h_lines) or self.__line_sweep(v_lines)
22+
23+
24+
def main():
25+
n = 5
26+
rectangles = [[1, 0, 5, 2], [0, 2, 2, 4], [3, 2, 5, 3], [0, 4, 4, 5]]
27+
assert Solution().checkValidCuts(n, rectangles) is True
28+
29+
n = 4
30+
rectangles = [[0, 0, 1, 1], [2, 0, 3, 4], [0, 2, 2, 3], [3, 0, 4, 3]]
31+
assert Solution().checkValidCuts(n, rectangles) is True
32+
33+
n = 4
34+
rectangles = [[0, 2, 2, 4], [1, 0, 3, 2], [2, 2, 3, 4], [3, 0, 4, 2], [3, 2, 4, 4]]
35+
assert Solution().checkValidCuts(n, rectangles) is False
36+
37+
38+
if __name__ == '__main__':
39+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
| March 22 | [2685. Count the Number of Complete Components](https://leetcode.com/problems/count-the-number-of-complete-components/) | Medium | Unsolved |
2929
| March 23 | [1976. Number of Ways to Arrive at Destination](https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/) | Medium | Unsolved |
3030
| March 24 | [3169. Count Days Without Meetings](https://leetcode.com/problems/count-days-without-meetings/) | Medium | Solved |
31-
| March 25 | []() | | |
31+
| March 25 | [3394. Check if Grid can be Cut into Sections](https://leetcode.com/problems/check-if-grid-can-be-cut-into-sections/) | Medium | Solved |
3232
| March 26 | []() | | |
3333
| March 27 | []() | | |
3434
| March 28 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 6 | 6 | 0 |
44-
| Medium | 17 | 7 | 10 |
44+
| Medium | 18 | 8 | 10 |
4545
| Hard | 1 | 0 | 1 |

0 commit comments

Comments
 (0)