Back to January Back to Year 2026
EASY 25 Jan 2026 View on LeetCode

1984. Minimum Difference Between Highest and Lowest of K Scores

</> Solution

/**
 * Problem: LeetCode 1984 - Minimum Difference Between Highest and Lowest of K Scores
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
import java.util.Arrays;

class Solution {
    public int minimumDifference(int[] nums, int k) {
        if (k <= 1) {
            return 0;
        }

        Arrays.sort(nums);
        int minDiff = Integer.MAX_VALUE;

        for (int i = 0; i + k - 1 < nums.length; i++) {
            int currentDiff = nums[i + k - 1] - nums[i];
            minDiff = Math.min(minDiff, currentDiff);
        }

        return minDiff;
    }
}

TIME COMPLEXITY

O(N log N)

SPACE COMPLEXITY

O(1)

TOPICS

Array Sliding Window Sorting