values of even length n and an integer limit. Split the array into mirror pairs: element i is paired with element n - 1 - i. The array is good when every mirror pair has the same sum.
One change replaces any element with any integer from 1 to limit inclusive. Return the minimum number of changes that make the array good.values=[3, 1, 2, 2], limit=3 → 1
The pairs are 3 + 2 = 5 and 1 + 2 = 3. Replace the 1 with a 3 and both pairs sum to 5: one change.
values=[1, 3, 3, 3], limit=3 → 1
The pairs sum to 4 and 6. Replacing the 1 with a 3 makes the first pair 3 + 3 = 6 as well, so the answer is 1.
values=[1, 1, 4, 4], limit=4 → 0
Both pairs already sum to 5.
values=[3, 1, 2, 2], limit=3
1
Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.