Class Solution
java.lang.Object
g2701_2800.s2772_apply_operations_to_make_all_array_elements_equal_to_zero.Solution
2772 - Apply Operations to Make All Array Elements Equal to Zero.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and a positive integer <code>k</code>.</p>
<p>You can apply the following operation on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>any</strong> subarray of size <code>k</code> from the array and <strong>decrease</strong> all its elements by <code>1</code>.</li>
</ul>
<p>Return <code>true</code> <em>if you can make all the array elements equal to</em> <code>0</code><em>, or</em> <code>false</code> <em>otherwise</em>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty part of an array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,2,3,1,1,0], k = 3</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong></p>
<p>We can do the following operations:</p>
<ul>
<li>
<p>Choose the subarray [2,2,3]. The resulting array will be nums = [<strong><ins>1</ins></strong> , <strong><ins>1</ins></strong> , <strong><ins>2</ins></strong> ,1,1,0].</p>
</li>
<li>
<p>Choose the subarray [2,1,1]. The resulting array will be nums = [1,1, <strong><ins>1</ins></strong> , <strong><ins>0</ins></strong> , <strong><ins>0</ins></strong> ,0].</p>
</li>
<li>
<p>Choose the subarray [1,1,1]. The resulting array will be nums = [<ins> <strong>0</strong> </ins>,<ins> <strong>0</strong> </ins>,<ins> <strong>0</strong> </ins>,0,0,0].</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,3,1,1], k = 2</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> It is not possible to make all the array elements equal to 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= k <= nums.length <= 10<sup>5</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
checkArray
public boolean checkArray(int[] nums, int k)
-