Minimum Moves to Make Array Complementary
You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.
The array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number.
Return the minimum number of moves required to make nums complementary.
Example 1
Input
nums = [1,2,4,3], limit = 4Output
1In 1 move, you can change
nums to [1, 2, 2, 3], making every mirrored pair sum to 4.Example 2
Input
nums = [1,2,2,1], limit = 2Output
2In 2 moves, you can change
nums to [2, 2, 2, 2], and values greater than limit are not allowed.Constraints
- n == nums.length
- 2 <= n <= 10^5
- 1 <= nums[i] <= limit <= 10^5
- n is even.