java.lang.Object
g1901_2000.s1984_minimum_difference_between_highest_and_lowest_of_k_scores.Solution

public class Solution extends Object
1984 - Minimum Difference Between Highest and Lowest of K Scores.<p>Easy</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, where <code>nums[i]</code> represents the score of the <code>i<sup>th</sup></code> student. You are also given an integer <code>k</code>.</p> <p>Pick the scores of any <code>k</code> students from the array so that the <strong>difference</strong> between the <strong>highest</strong> and the <strong>lowest</strong> of the <code>k</code> scores is <strong>minimized</strong>.</p> <p>Return <em>the <strong>minimum</strong> possible difference</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [90], k = 1</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There is one way to pick score(s) of one student:</p> <ul> <li>[<strong>90</strong> ]. The difference between the highest and lowest score is 90 - 90 = 0.</li> </ul> <p>The minimum possible difference is 0.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [9,4,1,7], k = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> There are six ways to pick score(s) of two students:</p> <ul> <li> <p>[<strong>9</strong> , <strong>4</strong> ,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.</p> </li> <li> <p>[<strong>9</strong> ,4, <strong>1</strong> ,7]. The difference between the highest and lowest score is 9 - 1 = 8.</p> </li> <li> <p>[<strong>9</strong> ,4,1, <strong>7</strong> ]. The difference between the highest and lowest score is 9 - 7 = 2.</p> </li> <li> <p>[9, <strong>4</strong> , <strong>1</strong> ,7]. The difference between the highest and lowest score is 4 - 1 = 3.</p> </li> <li> <p>[9, <strong>4</strong> ,1, <strong>7</strong> ]. The difference between the highest and lowest score is 7 - 4 = 3.</p> </li> <li> <p>[9,4, <strong>1</strong> , <strong>7</strong> ]. The difference between the highest and lowest score is 7 - 1 = 6.</p> </li> </ul> <p>The minimum possible difference is 2.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= k <= nums.length <= 1000</code></li> <li><code>0 <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimumDifference

      public int minimumDifference(int[] nums, int k)