3355. Zero Array Transformation I Medium
1/**
2 * [3355] Zero Array Transformation I
3 *
4 * You are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri].
5 * For each queries[i]:
6 *
7 * Select a <span data-keyword="subset">subset</span> of indices within the range [li, ri] in nums.
8 * Decrement the values at the selected indices by 1.
9 *
10 * A Zero Array is an array where all elements are equal to 0.
11 * Return true if it is possible to transform nums into a Zero Array after processing all the queries sequentially, otherwise return false.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,0,1], queries = [[0,2]]</span>
16 * Output: <span class="example-io">true</span>
17 * Explanation:
18 *
19 * For i = 0:
20 *
21 * Select the subset of indices as [0, 2] and decrement the values at these indices by 1.
22 * The array will become [0, 0, 0], which is a Zero Array.
23 *
24 *
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [4,3,2,1], queries = [[1,3],[0,2]]</span>
29 * Output: <span class="example-io">false</span>
30 * Explanation:
31 *
32 * For i = 0:
33 *
34 * Select the subset of indices as [1, 2, 3] and decrement the values at these indices by 1.
35 * The array will become [4, 2, 1, 0].
36 *
37 *
38 * For i = 1:
39 *
40 * Select the subset of indices as [0, 1, 2] and decrement the values at these indices by 1.
41 * The array will become [3, 1, 0, 0], which is not a Zero Array.
42 *
43 *
44 * </div>
45 *
46 * Constraints:
47 *
48 * 1 <= nums.length <= 10^5
49 * 0 <= nums[i] <= 10^5
50 * 1 <= queries.length <= 10^5
51 * queries[i].length == 2
52 * 0 <= li <= ri < nums.length
53 *
54 */
55pub struct Solution {}
56
57// problem: https://leetcode.com/problems/zero-array-transformation-i/
58// discuss: https://leetcode.com/problems/zero-array-transformation-i/discuss/?currentPage=1&orderBy=most_votes&query=
59
60// submission codes start here
61
62impl Solution {
63 pub fn is_zero_array(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> bool {
64 false
65 }
66}
67
68// submission codes end
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73
74 #[test]
75 fn test_3355() {
76 }
77}
78
Back
© 2025 bowen.ge All Rights Reserved.