File size: 2,079 Bytes
4097b71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
  "id": 2878,
  "name": "apply-operations-to-make-all-array-elements-equal-to-zero",
  "difficulty": "Medium",
  "link": "https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/",
  "date": "2023-07-02",
  "task_description": "You are given a **0-indexed** integer array `nums` and a positive integer `k`. You can apply the following operation on the array **any** number of times: Choose **any** subarray of size `k` from the array and **decrease** all its elements by `1`. Return `true`_ if you can make all the array elements equal to _`0`_, or _`false`_ otherwise_. 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 = [**1**,**1**,**2**,1,1,0]. - Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,**1**,**0**,**0**,0]. - Choose the subarray [1,1,1]. The resulting array will be nums = [**0**,**0**,**0**,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:** `1 <= k <= nums.length <= 105` `0 <= nums[i] <= 106`",
  "test_case": [
    {
      "label": "Example 1",
      "input": "nums = [2,2,3,1,1,0], k = 3",
      "output": "true "
    },
    {
      "label": "Example 2",
      "input": "nums = [1,3,1,1], k = 2",
      "output": "false "
    }
  ],
  "constraints": [
    "Choose any subarray of size k from the array and decrease all its elements by 1.",
    "1 <= k <= nums.length <= 105",
    "0 <= nums[i] <= 106"
  ],
  "python_template": "class Solution(object):\n    def checkArray(self, nums, k):\n        \"\"\"\n        :type nums: List[int]\n        :type k: int\n        :rtype: bool\n        \"\"\"\n        ",
  "java_template": "class Solution {\n    public boolean checkArray(int[] nums, int k) {\n        \n    }\n}",
  "metadata": {
    "func_name": "checkArray"
  }
}