3356. Zero Array Transformation II
You are given an integer array
nums
of lengthn
and a 2D arrayqueries
wherequeries[i] = [li, ri, vali]
.Each
queries[i]
represents the following action onnums
:
- Decrement the value at each index in the range
[li, ri]
innums
by at mostvali
.- The amount by which each value is decremented can be chosen independently for each index.
A Zero Array is an array with all its elements equal to 0.
Return the minimum possible non-negative value of
k
, such that after processing the firstk
queries in sequence,nums
becomes a Zero Array. If no suchk
exists, return -1.
1 | class Solution { |