java.lang.Object
g1701_1800.s1775_equal_sum_arrays_with_minimum_number_of_operations.Solution

public class Solution extends Object
1775 - Equal Sum Arrays With Minimum Number of Operations.<p>Medium</p> <p>You are given two arrays of integers <code>nums1</code> and <code>nums2</code>, possibly of different lengths. The values in the arrays are between <code>1</code> and <code>6</code>, inclusive.</p> <p>In one operation, you can change any integer&rsquo;s value in <strong>any</strong> of the arrays to <strong>any</strong> value between <code>1</code> and <code>6</code>, inclusive.</p> <p>Return <em>the minimum number of operations required to make the sum of values in</em> <code>nums1</code> <em>equal to the sum of values in</em> <code>nums2</code><em>.</em> Return <code>-1</code> if it is not possible to make the sum of the two arrays equal.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.</p> <ul> <li> <p>Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [<strong>6</strong> ,1,2,2,2,2].</p> </li> <li> <p>Change nums1[5] to 1. nums1 = [1,2,3,4,5, <strong>1</strong> ], nums2 = [6,1,2,2,2,2].</p> </li> <li> <p>Change nums1[2] to 2. nums1 = [1,2, <strong>2</strong> ,4,5,1], nums2 = [6,1,2,2,2,2].</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums1 = [1,1,1,1,1,1,1], nums2 = [6]</p> <p><strong>Output:</strong> -1</p> <p><strong>Explanation:</strong> There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums1 = [6,6], nums2 = [1]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.</p> <ul> <li> <p>Change nums1[0] to 2. nums1 = [<strong>2</strong> ,6], nums2 = [1].</p> </li> <li> <p>Change nums1[1] to 2. nums1 = [2, <strong>2</strong> ], nums2 = [1].</p> </li> <li> <p>Change nums2[0] to 4. nums1 = [2,2], nums2 = [<strong>4</strong> ].</p> </li> </ul> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums1[i], nums2[i] <= 6</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minOperations

      public int minOperations(int[] nums1, int[] nums2)