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

Open every published interview problem, solution, scene, and memory room free, with no account.

More Sorting problems