347. Minimum Moves to Make Array Complementary
MediumArray
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. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5. Return the minimum number of moves required to make nums complementary.
Examples
Input: [1,2,4,3] 4
Output: 1
Explanation: Public test case for Minimum Moves to Make Array Complementary
Constraints
- n == nums.length
- 2 <= n <= 10^5
- 1 <= nums[i] <= limit <= 10^5
- n is even.
Loading...
Run checks all cases above. Submit evaluates all test cases.