Tap here to switch tabs
Problem
Submissions

Problem: Minimum Score by Changing Two Elements

Minimum Score by Changing Two Elements asks you to modify at most two values in an integer array and return the smallest sum of the minimum and maximum absolute differences among distinct pairs.

Statement

You are given an integer array nums.

The low score of nums is the minimum absolute difference between any two elements at distinct indices, defined as min⁡∣\min | nums[i] −- nums[j] ∣| where 0≤i<j<0 \leq i < j < nums.length.

The high score of nums is the maximum absolute difference between any two elements at distinct indices, defined as max⁡∣\max | nums[i] −- nums[j] ∣| where 0≤i<j<0 \leq i < j < nums.length.

The total score of nums is the sum of its high score and low score.

Return the minimum possible total score of nums after modifying the values of at most 22 elements.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Score by Changing Two Elements

Minimum Score by Changing Two Elements asks you to modify at most two values in an integer array and return the smallest sum of the minimum and maximum absolute differences among distinct pairs.

Statement

You are given an integer array nums.

The low score of nums is the minimum absolute difference between any two elements at distinct indices, defined as min⁡∣\min | nums[i] −- nums[j] ∣| where 0≤i<j<0 \leq i < j < nums.length.

The high score of nums is the maximum absolute difference between any two elements at distinct indices, defined as max⁡∣\max | nums[i] −- nums[j] ∣| where 0≤i<j<0 \leq i < j < nums.length.

The total score of nums is the sum of its high score and low score.

Return the minimum possible total score of nums after modifying the values of at most 22 elements.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9