3224. Minimum Array Changes to Make Differences Equal Medium

@problem@discussion
#Array#Hash Table#Prefix Sum



1/**
2 * [3224] Minimum Array Changes to Make Differences Equal
3 *
4 * You are given an integer array nums of size n where n is even, and an integer k.
5 * 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 0 to k.
6 * You need to perform some changes (possibly none) such that the final array satisfies the following condition:
7 * 
8 * 	There exists an integer X such that abs(a[i] - a[n - i - 1]) = X for all (0 <= i < n).
9 * 
10 * Return the minimum number of changes required to satisfy the above condition.
11 *  
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [1,0,1,2,4,3], k = 4</span>
15 * Output: <span class="example-io">2</span>
16 * Explanation:<br />
17 * We can perform the following changes:
18 * 
19 * 	Replace nums[1] by 2. The resulting array is nums = [1,<u>2</u>,1,2,4,3].
20 * 	Replace nums[3] by 3. The resulting array is nums = [1,2,1,<u>3</u>,4,3].
21 * 
22 * The integer X will be 2.
23 * </div>
24 * <strong class="example">Example 2:
25 * <div class="example-block">
26 * Input: <span class="example-io">nums = [0,1,2,3,3,6,5,4], k = 6</span>
27 * Output: <span class="example-io">2</span>
28 * Explanation:<br />
29 * We can perform the following operations:
30 * 
31 * 	Replace nums[3] by 0. The resulting array is nums = [0,1,2,<u>0</u>,3,6,5,4].
32 * 	Replace nums[4] by 4. The resulting array is nums = [0,1,2,0,<u>4</u>,6,5,4].
33 * 
34 * The integer X will be 4.
35 * </div>
36 *  
37 * Constraints:
38 * 
39 * 	2 <= n == nums.length <= 10^5
40 * 	n is even.
41 * 	0 <= nums[i] <= k <= 10^5
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/minimum-array-changes-to-make-differences-equal/
47// discuss: https://leetcode.com/problems/minimum-array-changes-to-make-differences-equal/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn min_changes(nums: Vec<i32>, k: i32) -> i32 {
53        0
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_3224() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.