Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
minimum-operations-to-make-array-equal-ii.json32 linesDownload Raw Back to root
1{2  "id": 2604,3  "name": "minimum-operations-to-make-array-equal-ii",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/minimum-operations-to-make-array-equal-ii/",6  "date": "2023-01-07",7  "task_description": "You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`: Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`. `nums1` is said to be **equal** to `nums2` if for all indices `i` such that `0 <= i < n`, `nums1[i] == nums2[i]`. Return _the **minimum** number of operations required to make _`nums1`_ equal to _`nums2`. If it is impossible to make them equal, return `-1`. **Example 1:** ``` **Input:** nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3 **Output:** 2 **Explanation:** In 2 operations, we can transform nums1 to nums2. 1st operation: i = 2, j = 0. After applying the operation, nums1 = [1,3,4,4]. 2nd operation: i = 2, j = 3. After applying the operation, nums1 = [1,3,7,1]. One can prove that it is impossible to make arrays equal in fewer operations. ``` **Example 2:** ``` **Input:** nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1 **Output:** -1 **Explanation:** It can be proved that it is impossible to make the two arrays equal. ``` **Constraints:** `n == nums1.length == nums2.length` `2 <= n <= 105` `0 <= nums1[i], nums2[j] <= 109` `0 <= k <= 105`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3",12      "output": "2 "13    },14    {15      "label": "Example 2",16      "input": "nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1",17      "output": "-1 "18    }19  ],20  "constraints": [21    "Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.",22    "n == nums1.length == nums2.length",23    "2 <= n <= 105",24    "0 <= nums1[i], nums2[j] <= 109",25    "0 <= k <= 105"26  ],27  "python_template": "class Solution(object):\n    def minOperations(self, nums1, nums2, k):\n        \"\"\"\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :type k: int\n        :rtype: int\n        \"\"\"\n        ",28  "java_template": "class Solution {\n    public long minOperations(int[] nums1, int[] nums2, int k) {\n        \n    }\n}",29  "metadata": {30    "func_name": "minOperations"31  }32}