#3362

Zero Array Transformation III

specialist · 810 · lc medium +31 · 54.9% accepted · 692 likes · top 48%

Description

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

Each queries[i] performs the following on nums:

- Decrease each value at indices in [li, ri] by at most 1.

- The amount decremented at each index can be chosen independently.

A Zero Array has all elements equal to 0.

Return the maximum number of queries that can be removed while still allowing nums to be transformed into a Zero Array using the remaining queries. If it is impossible to make nums a Zero Array at all, return -1.

Code

1
2
3