#3356

Zero Array Transformation II

specialist · 965 · lc medium +32 · 43.6% accepted · 1,024 likes · top 25%

Description

You are given an integer array nums of length n and a 2D array queries where queries[i] = [li, ri, vali].

Each queries[i] performs the following on nums:

- Decrease each index in the range [li, ri] by at most vali.

- The decrement at each index may be chosen independently.

A Zero Array has all elements equal to 0.

Return the minimum non-negative integer k such that processing the first k queries transforms nums into a Zero Array, or -1 if no such k exists.

Code

1
2
3