Practice Zero Array Transformation II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
For an inclusive query [l, r, value], decrease each covered entry in nums by an independently chosen integer from 0 through value. Return the smallest nonnegative number k of initial queries that can make every entry zero when processed in order. If no prefix works, return -1.
Source: Zero Array Transformation II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [2,0,2], queries = [[0,2,1],[0,2,1],[1,1,3]]
Output
2
# Example 2
Input
nums = [4,3,2,1], queries = [[1,3,2],[0,2,1]]
Output
-1
Constraints
1 <= nums.length <= 10^5
0 <= nums[i] <= 5 * 10^5
1 <= queries.length <= 10^5
queries[i].length == 3
0 <= li <= ri < nums.length
1 <= vali <= 5
Related LeetCode Problems
Practice more problems similar to Zero Array Transformation II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.