package leetcode;

/**
 * https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/
 */
public class Problem1984 {
    public int minimumDifference(int[] nums, int k) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1984 prob = new Problem1984();
        System.out.println(prob.minimumDifference(new int[]{90}, 1)); // 0
        System.out.println(prob.minimumDifference(new int[]{9,4,1,7}, 2)); // 2
        System.out.println(prob.minimumDifference(new int[]{9,4,1,7}, 3)); // 5
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -231,82 +231,108 @@
     
-// TODO%0A        return 0
+int answer = 0;%0A        Arrays.sort(nums)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args
+for (int i = nums.length - 1; i - k + 1 %3E= 0; i--
 ) %7B%0A
@@ -343,280 +343,229 @@
     
+   
-Problem1984 prob = new Problem1984();%0A        System.out.println(prob.minimumDifference(new int%5B%5D%7B90%7D, 1)); // 0%0A        System.out.println(prob.minimumDifference(new int%5B%5D%7B9,4,1,7%7D, 2)); // 2%0A        System.out.println(prob.minimumDifference(new int%5B%5D%7B9,4,1,7%7D, 3)); // 5
+ if (i == nums.length - 1) %7B%0A                answer = nums%5Bi%5D - nums%5Bi - k + 1%5D;%0A            %7D else %7B%0A                answer = Math.min(answer, nums%5Bi%5D - nums%5Bi - k + 1%5D);%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1984