FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 3332,3 "name": "minimum-operations-to-exceed-threshold-value-ii",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii/",6 "date": "2024-02-17",7 "task_description": "You are given a **0-indexed** integer array `nums`, and an integer `k`. You are allowed to perform some operations on `nums`, where in a single operation, you can: Select the two **smallest** integers `x` and `y` from `nums`. Remove `x` and `y` from `nums`. Insert `(min(x, y) * 2 + max(x, y))` at any position in the array. **Note** that you can only apply the described operation if `nums` contains **at least** two elements. Return the **minimum** number of operations needed so that all elements of the array are **greater than or equal to** `k`. **Example 1:** **Input:** nums = [2,11,10,1,3], k = 10 **Output:** 2 **Explanation:** In the first operation, we remove elements 1 and 2, then add `1 * 2 + 2` to `nums`. `nums` becomes equal to `[4, 11, 10, 3]`. In the second operation, we remove elements 3 and 4, then add `3 * 2 + 4` to `nums`. `nums` becomes equal to `[10, 11, 10]`. At this stage, all the elements of nums are greater than or equal to 10 so we can stop. It can be shown that 2 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10. **Example 2:** **Input:** nums = [1,1,2,4,9], k = 20 **Output:** 4 **Explanation:** After one operation, `nums` becomes equal to `[2, 4, 9, 3]`. After two operations, `nums` becomes equal to `[7, 4, 9]`. After three operations, `nums` becomes equal to `[15, 9]`. After four operations, `nums` becomes equal to `[33]`. At this stage, all the elements of `nums` are greater than 20 so we can stop. It can be shown that 4 is the minimum number of operations needed so that all elements of the array are greater than or equal to 20. **Constraints:** `2 <= nums.length <= 2 * 105` `1 <= nums[i] <= 109` `1 <= k <= 109` The input is generated such that an answer always exists. That is, after performing some number of operations, all elements of the array are greater than or equal to `k`.",8 "test_case": [9 {10 "label": "Example 1",11 "input": "nums = [2,11,10,1,3], k = 10",12 "output": "2 "13 },14 {15 "label": "Example 2",16 "input": "nums = [1,1,2,4,9], k = 20",17 "output": "4 "18 }19 ],20 "constraints": [21 "Select the two smallest integers x and y from nums.",22 "Remove x and y from nums.",23 "Insert (min(x, y) * 2 + max(x, y)) at any position in the array.",24 "2 <= nums.length <= 2 * 105",25 "1 <= nums[i] <= 109",26 "1 <= k <= 109",27 "The input is generated such that an answer always exists. That is, after performing some number of operations, all elements of the array are greater than or equal to k."28 ],29 "python_template": "class Solution(object):\n def minOperations(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",30 "java_template": "class Solution {\n public int minOperations(int[] nums, int k) {\n \n }\n}",31 "metadata": {32 "func_name": "minOperations"33 }34}