Given two arrays, A and B, where each array contains values between 1-6 representing the faces of a dice,
return the minimum number of dice flips so that the sum of both arrays is equal, or -1 if this is impossible.
Examples
Input: A = [1, 2, 3, 2, 1] B = [6]
Answer: 2
Explanation: replace 3 by 1 and one of the 2's by 1. The sum becomes 1 + 2 + 1 + 1 + 1 = 6.
Input: A = [3, 3, 3, 3, 3, 3, 3] B = [1]
Answer: -1
Explanation: The minimum sum for A is 7, the maximum sum for B is 6.
Input: A = [3, 4, 6] B = [6, 2]
Answer: 2
Explanation: Replace A's 3 by 2, and B's 2 by 6.
I believe this is related to both
1737. Change Minimum Characters to Satisfy One of Three Conditions
And
My attempt at a solution was to use DP while assuming the only useful changes are n->1 for the array with greater sum and n->6 for the array with lower sum until the sum difference hits 0 (except when the sum < new value - current value of course), but after idly thinking about it more, I think it might actually require a full exploration...