|
| 1 | +You are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri]. |
| 2 | + |
| 3 | +For each queries[i]: |
| 4 | + |
| 5 | +Select a subset of indices within the range [li, ri] in nums. |
| 6 | +Decrement the values at the selected indices by 1. |
| 7 | +A Zero Array is an array where all elements are equal to 0. |
| 8 | + |
| 9 | +Return true if it is possible to transform nums into a Zero Array after processing all the queries sequentially, otherwise return false. |
| 10 | + |
| 11 | + |
| 12 | +class Solution: |
| 13 | + def isZeroArray(self, nums: List[int], queries: List[List[int]]) -> bool: |
| 14 | + |
| 15 | + pref = [0]*len(nums) |
| 16 | + for q in queries: |
| 17 | + a,b = q |
| 18 | + for i in range(a,b+1): |
| 19 | + pref[i] +=1 |
| 20 | + |
| 21 | + print(pref) |
| 22 | + |
| 23 | + if any( p<n for n,p in zip(nums,pref)): |
| 24 | + return False |
| 25 | + |
| 26 | + return True |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +------------------------------------------------------------------------------------- |
0 commit comments