Class Solution
-
- All Implemented Interfaces:
public final class Solution3224 - Minimum Array Changes to Make Differences Equal\.
Medium
You are given an integer array
numsof sizenwherenis even , and an integerk.You can perform some changes on the array, where in one change you can replace any element in the array with any integer in the range from
0tok.You need to perform some changes (possibly none) such that the final array satisfies the following condition:
There exists an integer
Xsuch thatabs(a[i] - a[n - i - 1]) = Xfor all(0 <= i < n).
Return the minimum number of changes required to satisfy the above condition.
Example 1:
Input: nums = 1,0,1,2,4,3, k = 4
Output: 2
Explanation: We can perform the following changes:
Replace
nums[1]by 2. The resulting array is <code>nums = 1,<ins> **2** </ins>,1,2,4,3</code>.Replace
nums[3]by 3. The resulting array is <code>nums = 1,2,1,<ins> **3** </ins>,4,3</code>.
The integer
Xwill be 2.Example 2:
Input: nums = 0,1,2,3,3,6,5,4, k = 6
Output: 2
Explanation: We can perform the following operations:
Replace
nums[3]by 0. The resulting array is <code>nums = 0,1,2,<ins> **0** </ins>,3,6,5,4</code>.Replace
nums[4]by 4. The resulting array is <code>nums = 0,1,2,0, **<ins>4</ins>** ,6,5,4</code>.
The integer
Xwill be 4.Constraints:
<code>2 <= n == nums.length <= 10<sup>5</sup></code>
nis even.<code>0 <= numsi<= k <= 10<sup>5</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminChanges(IntArray nums, Integer k)-
-
Method Detail
-
minChanges
final Integer minChanges(IntArray nums, Integer k)
-
-
-
-