TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 3178,3 "name": "minimum_increment_operations_to_make_array_beautiful",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/minimum-increment-operations-to-make-array-beautiful/",6 "date": "2023-10-22 00:00:00",7 "task_description": "You are given a **0-indexed** integer array `nums` having length `n`, and an integer `k`. You can perform the following **increment** operation **any** number of times (**including zero**): Choose an index `i` in the range `[0, n - 1]`, and increase `nums[i]` by `1`. An array is considered **beautiful** if, for any **subarray** with a size of `3` or **more**, its **maximum** element is **greater than or equal** to `k`. Return _an integer denoting the **minimum** number of increment operations needed to make _`nums`_ **beautiful**._ A subarray is a contiguous **non-empty** sequence of elements within an array. **Example 1:** ``` **Input:** nums = [2,3,0,0,2], k = 4 **Output:** 3 **Explanation:** We can perform the following increment operations to make nums beautiful: Choose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2]. Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3]. Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4]. The subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4]. In all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful. It can be shown that nums cannot be made beautiful with fewer than 3 increment operations. Hence, the answer is 3. ``` **Example 2:** ``` **Input:** nums = [0,1,3,3], k = 5 **Output:** 2 **Explanation:** We can perform the following increment operations to make nums beautiful: Choose index i = 2 and increase nums[2] by 1 -> [0,1,4,3]. Choose index i = 2 and increase nums[2] by 1 -> [0,1,5,3]. The subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3]. In all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful. It can be shown that nums cannot be made beautiful with fewer than 2 increment operations. Hence, the answer is 2. ``` **Example 3:** ``` **Input:** nums = [1,1,2], k = 1 **Output:** 0 **Explanation:** The only subarray with a size of 3 or more in this example is [1,1,2]. The maximum element, 2, is already greater than k = 1, so we don't need any increment operation. Hence, the answer is 0. ``` **Constraints:** `3 <= n == nums.length <= 105` `0 <= nums[i] <= 109` `0 <= k <= 109`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [2,3,0,0,2], k = 4",12 "output": "3 "13 },14 {15 "label": "Example 2",16 "input": "nums = [0,1,3,3], k = 5",17 "output": "2 "18 },19 {20 "label": "Example 3",21 "input": "nums = [1,1,2], k = 1",22 "output": "0 "23 }24 ],25 "private_test_cases": [26 {27 "input": [28 [29 462325066,30 206420187,31 521315460,32 318264093,33 66475813,34 619438353,35 499937120,36 9685155,37 2855537,38 91394424039 ],40 37317346041 ],42 "output": 043 },44 {45 "input": [46 [47 317576829,48 230943442,49 194377313,50 217961295,51 179889103,52 421788827,53 346731151,54 31378563,55 45721552856 ],57 66394453258 ],59 "output": 91845192860 },61 {62 "input": [63 [64 554240499,65 168910099,66 370475323,67 72793279,68 181768111,69 41525500170 ],71 17984258072 ],73 "output": 074 },75 {76 "input": [77 [78 168413874,79 337615557,80 757898546,81 697884066,82 97110609,83 987627695,84 755555424,85 530718081,86 97600269187 ],88 94489376389 ],90 "output": 18699521791 },92 {93 "input": [94 [95 484598604,96 491482864,97 339460418,98 940057113,99 528767250,100 102185549101 ],102 189117733103 ],104 "output": 0105 },106 {107 "input": [108 [109 719164977,110 892326581,111 957540324,112 991726451,113 280307765,114 41099724,115 871482641116 ],117 740459607118 ],119 "output": 0120 },121 {122 "input": [123 [124 49010645,125 338826954,126 801318173,127 348190584,128 354157732,129 232141023130 ],131 94104474132 ],133 "output": 0134 },135 {136 "input": [137 [138 305762391,139 417436427,140 338549371,141 153703212142 ],143 649513426144 ],145 "output": 232076999146 },147 {148 "input": [149 [150 220369410,151 282934213,152 198247569,153 726195262,154 41979645,155 117267716,156 555256808,157 683741535,158 880011605,159 218580428160 ],161 493276257162 ],163 "output": 210342044164 },165 {166 "input": [167 [168 902477971,169 881152273,170 639491946,171 510273653,172 365179409173 ],174 422822051175 ],176 "output": 0177 }178 ],179 "haskell_template": "minIncrementOperations :: [Int] -> Int -> Int\nminIncrementOperations nums k ",180 "ocaml_template": "let minIncrementOperations (nums: int list) (k: int) : int = ",181 "scala_template": "def minIncrementOperations(nums: List[Int],k: Int): Int = { \n \n}",182 "java_template": "class Solution {\n public long minIncrementOperations(int[] nums, int k) {\n \n }\n}",183 "python_template": "class Solution(object):\n def minIncrementOperations(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n "184}