Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes402downloads
find-minimum-cost-to-remove-array-elements.json35 linesDownload Raw Back to root
1{2  "id": 3776,3  "name": "find-minimum-cost-to-remove-array-elements",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/find-minimum-cost-to-remove-array-elements/",6  "date": "2025-02-15",7  "task_description": "You are given an integer array `nums`. Your task is to remove **all elements** from the array by performing one of the following operations at each step until `nums` is empty: Choose any two elements from the first three elements of `nums` and remove them. The cost of this operation is the **maximum** of the two elements removed. If fewer than three elements remain in `nums`, remove all the remaining elements in a single operation. The cost of this operation is the **maximum** of the remaining elements. Return the **minimum** cost required to remove all the elements. **Example 1:** **Input:** nums = [6,2,8,4] **Output:** 12 **Explanation:** Initially, `nums = [6, 2, 8, 4]`. In the first operation, remove `nums[0] = 6` and `nums[2] = 8` with a cost of `max(6, 8) = 8`. Now, `nums = [2, 4]`. In the second operation, remove the remaining elements with a cost of `max(2, 4) = 4`. The cost to remove all elements is `8 + 4 = 12`. This is the minimum cost to remove all elements in `nums`. Hence, the output is 12. **Example 2:** **Input:** nums = [2,1,3,3] **Output:** 5 **Explanation:** Initially, `nums = [2, 1, 3, 3]`. In the first operation, remove `nums[0] = 2` and `nums[1] = 1` with a cost of `max(2, 1) = 2`. Now, `nums = [3, 3]`. In the second operation remove the remaining elements with a cost of `max(3, 3) = 3`. The cost to remove all elements is `2 + 3 = 5`. This is the minimum cost to remove all elements in `nums`. Hence, the output is 5. **Constraints:** `1 <= nums.length <= 1000` `1 <= nums[i] <= 106`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [6,2,8,4]",12      "output": "12 "13    },14    {15      "label": "Example 2",16      "input": "nums = [2,1,3,3]",17      "output": "5 "18    }19  ],20  "constraints": [21    "Choose any two elements from the first three elements of nums and remove them. The cost of this operation is the maximum of the two elements removed.",22    "If fewer than three elements remain in nums, remove all the remaining elements in a single operation. The cost of this operation is the maximum of the remaining elements.",23    "In the first operation, remove nums[0] = 6 and nums[2] = 8 with a cost of max(6, 8) = 8. Now, nums = [2, 4].",24    "In the second operation, remove the remaining elements with a cost of max(2, 4) = 4.",25    "In the first operation, remove nums[0] = 2 and nums[1] = 1 with a cost of max(2, 1) = 2. Now, nums = [3, 3].",26    "In the second operation remove the remaining elements with a cost of max(3, 3) = 3.",27    "1 <= nums.length <= 1000",28    "1 <= nums[i] <= 106"29  ],30  "python_template": "class Solution(object):\n    def minCost(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        ",31  "java_template": "class Solution {\n    public int minCost(int[] nums) {\n        \n    }\n}",32  "metadata": {33    "func_name": "minCost"34  }35}