Medium · Sorting

Equal Sum Arrays with Minimum Number of Operations

Given two arrays nums1 and nums2 of dice values 1–6, where one operation changes any single value in either array to any value from 1 to 6, return the minimum number of operations that makes the two sums equal, or -1 if that is impossible.

Examples

Example 1

[1,2,3,4,5,6] vs [1,1,2,2,2,2]

Output: 3 ops

Example 2

[1,1,1,1,1,1,1] vs [6]

Output: -1 (impossible)

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Sorting problems