values of even length n and an integer limit. Split the array into mirrored pairs: the first element with the last, the second with the second-to-last, and so on.
In one change you may overwrite any element with any integer from 0 to limit inclusive.
The goal is for every mirrored pair to have the same absolute difference: there must be some X such that |values[i] - values[n - 1 - i]| = X for every i. You pick X.
Return the minimum number of changes.values=[3, 1, 4, 4, 0, 2], limit=5 → 1
The mirrored pairs are (3, 2), (1, 0) and (4, 4). The first two already differ by 1; in the third, replacing one 4 with 5 does the job. One change.
values=[0, 0, 1, 5, 5, 0], limit=5 → 2
The gaps in pairs (0, 0), (0, 5), (1, 5) are 0, 5 and 4, all different, so at most one pair can stay as is. Each of the other two needs one change.
values=[3, 1, 4, 4, 0, 2], limit=5
1
Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.