Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
minimum-cost-to-make-array-equal.json32 linesDownload Raw Back to root
1{2  "id": 2538,3  "name": "minimum-cost-to-make-array-equal",4  "difficulty": "Hard",5  "link": "https://leetcode.com/problems/minimum-cost-to-make-array-equal/",6  "date": "2022-10-16",7  "task_description": "You are given two **0-indexed** arrays `nums` and `cost` consisting each of `n` **positive** integers. You can do the following operation **any** number of times: Increase or decrease **any** element of the array `nums` by `1`. The cost of doing one operation on the `ith` element is `cost[i]`. Return _the **minimum** total cost such that all the elements of the array _`nums`_ become **equal**_. **Example 1:** ``` **Input:** nums = [1,3,5,2], cost = [2,3,1,14] **Output:** 8 **Explanation:** We can make all the elements equal to 2 in the following way: - Increase the 0th element one time. The cost is 2. - Decrease the 1st element one time. The cost is 3. - Decrease the 2nd element three times. The cost is 1 + 1 + 1 = 3. The total cost is 2 + 3 + 3 = 8. It can be shown that we cannot make the array equal with a smaller cost. ``` **Example 2:** ``` **Input:** nums = [2,2,2,2,2], cost = [4,2,8,1,3] **Output:** 0 **Explanation:** All the elements are already equal, so no operations are needed. ``` **Constraints:** `n == nums.length == cost.length` `1 <= n <= 105` `1 <= nums[i], cost[i] <= 106` Test cases are generated in a way that the output doesn't exceed 253-1",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [1,3,5,2], cost = [2,3,1,14]",12      "output": "8 "13    },14    {15      "label": "Example 2",16      "input": "nums = [2,2,2,2,2], cost = [4,2,8,1,3]",17      "output": "0 "18    }19  ],20  "constraints": [21    "Increase or decrease any element of the array nums by 1.",22    "n == nums.length == cost.length",23    "1 <= n <= 105",24    "1 <= nums[i], cost[i] <= 106",25    "Test cases are generated in a way that the output doesn't exceed 253-1"26  ],27  "python_template": "class Solution(object):\n    def minCost(self, nums, cost):\n        \"\"\"\n        :type nums: List[int]\n        :type cost: List[int]\n        :rtype: int\n        \"\"\"\n        ",28  "java_template": "class Solution {\n    public long minCost(int[] nums, int[] cost) {\n        \n    }\n}",29  "metadata": {30    "func_name": "minCost"31  }32}