Minimum Score by Changing Two Elements - Problem
You are given an integer array nums.
The low score of nums is the minimum absolute difference between any two integers.
The high score of nums is the maximum absolute difference between any two integers.
The score of nums is the sum of the high and low scores.
Return the minimum score after changing two elements of nums.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,4,3]
›
Output:
0
💡 Note:
Change nums to [4,4,4]. Low score = 0 (min difference), High score = 0 (max-min), Total = 0+0 = 0
Example 2 — Different Values
$
Input:
nums = [1,4,7,8,5]
›
Output:
3
💡 Note:
Change to [4,4,5,5,5]. Low score = 1 (difference between 4 and 5), High score = 1 (5-4), Total = 1+1 = 2. Actually optimal is changing to get score 3.
Example 3 — Small Array
$
Input:
nums = [10,20]
›
Output:
0
💡 Note:
Change both elements to same value, e.g., [20,20]. Low score = 0, High score = 0, Total = 0
Constraints
- 3 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [1,4,3] with current low and high scores
2
Process
Change two elements to minimize total score
3
Output
Return minimum possible score after changes
Key Takeaway
🎯 Key Insight: Making elements equal or close to equal minimizes both the minimum difference and the range
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code