Class Solution
-
- All Implemented Interfaces:
public final class Solution2772 - Apply Operations to Make All Array Elements Equal to Zero.
Medium
You are given a 0-indexed integer array
numsand a positive integerk.You can apply the following operation on the array any number of times:
Choose any subarray of size
kfrom the array and decrease all its elements by1.
Return
trueif you can make all the array elements equal to0, orfalseotherwise.A subarray is a contiguous non-empty part of an array.
Example 1:
Input: nums = 2,2,3,1,1,0, k = 3
Output: true
Explanation:
We can do the following operations:
Choose the subarray 2,2,3. The resulting array will be nums = **<ins>1</ins>** , **<ins>1</ins>** , **<ins>2</ins>** ,1,1,0.
Choose the subarray 2,1,1. The resulting array will be nums = 1,1, **<ins>1</ins>** , **<ins>0</ins>** , **<ins>0</ins>** ,0.
Choose the subarray 1,1,1. The resulting array will be nums = <ins> **0** </ins>,<ins> **0** </ins>,<ins> **0** </ins>,0,0,0.
Example 2:
Input: nums = 1,3,1,1, k = 2
Output: false
Explanation: It is not possible to make all the array elements equal to 0.
Constraints:
<code>1 <= k <= nums.length <= 10<sup>5</sup></code>
<code>0 <= numsi<= 10<sup>6</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleancheckArray(IntArray nums, Integer k)-
-
Method Detail
-
checkArray
final Boolean checkArray(IntArray nums, Integer k)
-
-
-
-