Practice Zero Array Transformation III
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#3362
LeetCode ProblemZero Array Transformation III
Problem Statement
Each inclusive query [l, r] can decrease every covered nums entry by either 0 or 1, independently for each index. Return the maximum number of queries that can be discarded while the retained queries can still make every entry zero. Return -1 if even all queries cannot do so.
Source: Zero Array Transformation III on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [2,0,2], queries = [[0,2],[0,2],[1,1]]
Output
1
# Example 2
Input
nums = [1,1,1,1], queries = [[1,3],[0,2],[1,3],[1,2]]
Output
2
# Example 3
Input
nums = [1,2,3,4], queries = [[0,3]]
Output
-1
Constraints
1 <= nums.length <= 10^5
0 <= nums[i] <= 10^5
1 <= queries.length <= 10^5
queries[i].length == 2
0 <= li <= ri < nums.length
Related LeetCode Problems
Practice more problems similar to Zero Array Transformation III.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.