Do the Range Decrements Zero the Array
Problem statement
You have an array nums of positive integers and a list of ranges queries. Applying a range [l, r] lowers every number at indexes l through r (both included) by exactly 1.
After applying every range once, is the array all zeros? Return true if every number ends at exactly 0, and false otherwise (a number lowered too many times ends below 0, which also counts as false).
Function
canReachZero(nums: int[], queries: int[][]) → booleanExamples
Example 1
nums = [1,2,1]queries = [[0,1],[1,2]]return = trueThe first query lowers indexes 0 and 1, the second lowers 1 and 2. Index 1 is lowered twice and the others once, matching [1, 2, 1] exactly: true.
Example 2
nums = [2,1]queries = [[0,1]]return = falseOne query lowers both numbers once, leaving [1, 0]: false.
Example 3
nums = [1,1]queries = [[0,1],[1,1]]return = falseIndex 1 is lowered twice and ends at -1, not 0: false.
Constraints
1 <= nums.length <= 2000and1 <= nums[i] <= 20001 <= queries.length <= 2000, eachqueries[j] = [l, r]with0 <= l <= r < nums.length