Skip to content

Practice Equal Sum Arrays With Minimum Number of Operations

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1775
LeetCode Problem

Equal Sum Arrays With Minimum Number of Operations

Problem Statement

You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive. In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive. Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1​​​​​ if it is not possible to make the sum of the two arrays equal.

Source: Equal Sum Arrays With Minimum Number of Operations on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]
Output
3

# Example 2

Input
nums1 = [1,1,1,1,1,1,1], nums2 = [6]
Output
-1

# Example 3

Input
nums1 = [6,6], nums2 = [1]
Output
3

Constraints

1 <= nums1.length, nums2.length <= 10^5
1 <= nums1[i], nums2[i] <= 6

Related LeetCode Problems

Practice more problems similar to Equal Sum Arrays With Minimum Number of Operations.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.