java.lang.Object
g2501_2600.s2567_minimum_score_by_changing_two_elements.Solution

public class Solution extends Object
2567 - Minimum Score by Changing Two Elements.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p> <ul> <li>The <strong>low</strong> score of <code>nums</code> is the minimum value of <code>|nums[i] - nums[j]|</code> over all <code>0 <= i < j < nums.length</code>.</li> <li>The <strong>high</strong> score of <code>nums</code> is the maximum value of <code>|nums[i] - nums[j]|</code> over all <code>0 <= i < j < nums.length</code>.</li> <li>The <strong>score</strong> of <code>nums</code> is the sum of the <strong>high</strong> and <strong>low</strong> scores of nums.</li> </ul> <p>To minimize the score of <code>nums</code>, we can change the value of <strong>at most two</strong> elements of <code>nums</code>.</p> <p>Return _the <strong>minimum</strong> possible <strong>score</strong> after changing the value of <strong>at most two</strong> elements o_f <code>nums</code>.</p> <p>Note that <code>|x|</code> denotes the absolute value of <code>x</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,4,3]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> Change value of nums[1] and nums[2] to 1 so that nums becomes [1,1,1]. Now, the value of <code>|nums[i] - nums[j]|</code> is always equal to 0, so we return 0 + 0 = 0.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,4,7,8,5]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> Change nums[0] and nums[1] to be 6. Now nums becomes [6,6,7,8,5].</p> <p>Our low score is achieved when i = 0 and j = 1, in which case |<code>nums[i] - nums[j]</code>| = |6 - 6| = 0.</p> <p>Our high score is achieved when i = 3 and j = 4, in which case |<code>nums[i] - nums[j]</code>| = |8 - 5| = 3.</p> <p>The sum of our high and low score is 3, which we can prove to be minimal.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>3 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimizeSum

      public int minimizeSum(int[] nums)