Skip to content

Commit 87c2ae5

Browse files
committed
May 22
1 parent be56a18 commit 87c2ae5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

2025-05-May-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
| May 19 | [3024. Type of Triangle](https://leetcode.com/problems/type-of-triangle/) | Easy | Solved |
2626
| May 20 | [3355. Zero Array Transformation I](https://leetcode.com/problems/zero-array-transformation-i/) | Medium | Solved |
2727
| May 21 | [73. Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | Medium | Solved |
28-
| May 22 | []() | | |
28+
| May 22 | [3362. Zero Array Transformation III](https://leetcode.com/problems/zero-array-transformation-iii/) | Medium | Unsolved |
2929
| May 23 | []() | | |
3030
| May 24 | []() | | |
3131
| May 25 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 5 | 5 | 0 |
44-
| Medium | 11 | 9 | 2 |
44+
| Medium | 12 | 9 | 3 |
4545
| Hard | 4 | 1 | 3 |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from heapq import heappop, heappush
2+
3+
4+
class Solution:
5+
def maxRemoval(self, nums: list[int], queries: list[list[int]]) -> int:
6+
queries.sort() # queries.sort(lambda q: q[0])
7+
available, assigned = [], []
8+
count, ptr = 0, 0
9+
for time in range(len(nums)):
10+
while assigned and assigned[0] < time:
11+
heappop(assigned)
12+
while ptr < len(queries) and queries[ptr][0] <= time:
13+
heappush(available, -queries[ptr][1])
14+
ptr += 1
15+
while len(assigned) < nums[time] and available and -available[0] >= time:
16+
heappush(assigned, -heappop(available))
17+
count += 1
18+
if len(assigned) < nums[time]:
19+
return -1
20+
return len(queries) - count
21+
22+
23+
def main():
24+
nums = [2, 0, 2]
25+
queries = [[0, 2], [0, 2], [1, 1]]
26+
assert Solution().maxRemoval(nums, queries) == 1
27+
28+
nums = [1, 1, 1, 1]
29+
queries = [[1, 3], [0, 2], [1, 3], [1, 2]]
30+
assert Solution().maxRemoval(nums, queries) == 2
31+
32+
nums = [1, 2, 3, 4]
33+
queries = [[0, 3]]
34+
assert Solution().maxRemoval(nums, queries) == -1
35+
36+
37+
if __name__ == '__main__':
38+
main()

0 commit comments

Comments
 (0)