https://leetcode.com/problems/zero-array-transformation-i/Diff array stuff. This one was tough to conceptualize. If you actually loop through the L to R of each query it'll time you out for n*2 time complexity. So its actually like a presum where each index of diff represents the maximum you can subtract from the input array to try and get each element to zero.
class Solution:
def isZeroArray(self, nums: List[int], queries: List[List[int]]) -> bool:
diff = [0] * (len(nums)+1)
for l,r in queries:
diff[l] += 1
diff[r+1] -= 1
max_diff = 0
for i, n in enumerate(nums):
max_diff += diff[i]
if n - max_diff > 0:
return False
return True