left and right hold the values on their top faces (1 to 6). The rows may have different numbers of dice.
In one move you can pick any die in either row and turn it to show any face, which replaces its value with any number from 1 to 6.
Return the smallest number of moves that makes the two rows add up to the same total, or -1 if that cannot be done.left=[2, 2], right=[6] → 1
The sums are 4 and 6. Turning the right die to show 4 is enough.
left=[1, 2], right=[6, 6] → 2
The sums are 3 and 12, a gap of 9. One turn moves a sum by at most 5, so at least two are needed: for example, turn the left 1 into a 6 and one right 6 into a 2, giving 8 and 8.
left=[1, 1, 1, 1, 1, 1, 1, 1], right=[5] → -1
The left sum can never drop below 8, and the right sum can never exceed 6, so they cannot be made equal.
left), len(right) ≤ 10⁵left[i], right[i] ≤ 6left=[2, 2], right=[6]
1
Run checks the first 3 tests in your browser. Submit checks all 140 tests on the server, hidden ones included.