2567. Minimum Score by Changing Two Elements Medium
1/**
2 * [2567] Minimum Score by Changing Two Elements
3 *
4 * You are given an integer array nums.
5 *
6 * The low score of nums is the minimum absolute difference between any two integers.
7 * The high score of nums is the maximum absolute difference between any two integers.
8 * The score of nums is the sum of the high and low scores.
9 *
10 * Return the minimum score after changing two elements of nums.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [1,4,7,8,5]</span>
15 * Output: <span class="example-io">3</span>
16 * Explanation:
17 *
18 * Change nums[0] and nums[1] to be 6 so that nums becomes [6,6,7,8,5].
19 * The low score is the minimum absolute difference: |6 - 6| = 0.
20 * The high score is the maximum absolute difference: |8 - 5| = 3.
21 * The sum of high and low score is 3.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [1,4,3]</span>
26 * Output: <span class="example-io">0</span>
27 * Explanation:
28 *
29 * Change nums[1] and nums[2] to 1 so that nums becomes [1,1,1].
30 * The sum of maximum absolute difference and minimum absolute difference is 0.
31 * </div>
32 *
33 * Constraints:
34 *
35 * 3 <= nums.length <= 10^5
36 * 1 <= nums[i] <= 10^9
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/minimum-score-by-changing-two-elements/
42// discuss: https://leetcode.com/problems/minimum-score-by-changing-two-elements/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn minimize_sum(nums: Vec<i32>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_2567() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.