Skip to content

Commit f4d2e15

Browse files
committed
May 20
1 parent 449f81c commit f4d2e15

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| May 17 | [75. Sort Colors](https://leetcode.com/problems/sort-colors/) | Medium | Solved |
2424
| May 18 | [1931. Painting a Grid With Three Different Colors](https://leetcode.com/problems/painting-a-grid-with-three-different-colors/) | Hard | Unsolved |
2525
| May 19 | [3024. Type of Triangle](https://leetcode.com/problems/type-of-triangle/) | Easy | Solved |
26-
| May 20 | []() | | |
26+
| May 20 | [3355. Zero Array Transformation I](https://leetcode.com/problems/zero-array-transformation-i/) | Medium | Solved |
2727
| May 21 | []() | | |
2828
| May 22 | []() | | |
2929
| May 23 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 5 | 5 | 0 |
44-
| Medium | 9 | 7 | 2 |
44+
| Medium | 10 | 8 | 2 |
4545
| Hard | 4 | 1 | 3 |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from itertools import accumulate
2+
3+
4+
class Solution:
5+
def isZeroArray(self, nums: list[int], queries: list[list[int]]) -> bool:
6+
diff_array = [0] * (len(nums) + 1)
7+
for start, finish in queries:
8+
diff_array[start] += 1
9+
diff_array[min(finish + 1, len(nums))] -= 1
10+
prefix_sum = list(accumulate(diff_array))[:-1]
11+
return all(num <= curr_sum for num, curr_sum in zip(nums, prefix_sum))
12+
13+
14+
def main():
15+
nums = [1, 0, 1]
16+
queries = [[0, 2]]
17+
assert Solution().isZeroArray(nums, queries) is True
18+
19+
nums = [4, 3, 2, 1]
20+
queries = [[1, 3], [0, 2]]
21+
assert Solution().isZeroArray(nums, queries) is False
22+
23+
24+
if __name__ == '__main__':
25+
main()

0 commit comments

Comments
 (0)