2772. Apply Operations to Make All Array Elements Equal to Zero Medium

@problem@discussion
#Array#Prefix Sum



1/**
2 * [2772] Apply Operations to Make All Array Elements Equal to Zero
3 *
4 * You are given a 0-indexed integer array nums and a positive integer k.
5 * You can apply the following operation on the array any number of times:
6 * 
7 * 	Choose any subarray of size k from the array and decrease all its elements by 1.
8 * 
9 * Return true if you can make all the array elements equal to 0, or false otherwise.
10 * A subarray is a contiguous non-empty part of an array.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: nums = [2,2,3,1,1,0], k = 3
15 * Output: true
16 * Explanation: We can do the following operations:
17 * - Choose the subarray [2,2,3]. The resulting array will be nums = [<u>1</u>,<u>1</u>,<u>2</u>,1,1,0].
18 * - Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,<u>1</u>,<u>0</u>,<u>0</u>,0].
19 * - Choose the subarray [1,1,1]. The resulting array will be nums = [<u>0</u>,<u>0</u>,<u>0</u>,0,0,0].
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: nums = [1,3,1,1], k = 2
24 * Output: false
25 * Explanation: It is not possible to make all the array elements equal to 0.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= k <= nums.length <= 10^5
31 * 	0 <= nums[i] <= 10^6
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/
37// discuss: https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn check_array(nums: Vec<i32>, k: i32) -> bool {
43        false
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2772() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.