Tap here to switch tabs
Problem
Submissions

Problem: Minimum Score by Changing Two Elements

med
30 min
Try to solve the Minimum Score by Changing Two Elements problem.

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

med
30 min
Try to solve the Minimum Score by Changing Two Elements problem.

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