Class Solution
-
- All Implemented Interfaces:
public final class Solution3355 - Zero Array Transformation I.
Medium
You are given an integer array
numsof lengthnand a 2D arrayqueries, where <code>queriesi = l<sub>i</sub>, r<sub>i</sub></code>.For each
queries[i]:Select a subset of indices within the range <code>l<sub>i</sub>, r<sub>i</sub></code> in
nums.Decrement the values at the selected indices by 1.
A Zero Array is an array where all elements are equal to 0.
Return
trueif it is possible to transformnumsinto a Zero Array after processing all the queries sequentially, otherwise returnfalse.A subset of an array is a selection of elements (possibly none) of the array.
Example 1:
Input: nums = 1,0,1, queries = \[\[0,2]]
Output: true
Explanation:
For i = 0:
Example 2:
Input: nums = 4,3,2,1, queries = \[\[1,3],0,2]
Output: false
Explanation:
For i = 0:
For i = 1:
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
<code>0 <= numsi<= 10<sup>5</sup></code>
<code>1 <= queries.length <= 10<sup>5</sup></code>
queries[i].length == 2<code>0 <= l<sub>i</sub><= r<sub>i</sub>< nums.length</code>