Leetcode Problem 1984. Minimum Difference Between Highest and Lowest of K Scores

1984. Minimum Difference Between Highest and Lowest of K Scores

Leetcode Solutions

Sliding Window on Sorted Array

  • Sort the array nums in non-decreasing order.\n- Initialize minDifference to a large value.\n- Iterate over the array with a window of size k:\n - For each window, calculate the difference between the last and first elements in the window.\n - Update minDifference if the current difference is smaller.\n- Return minDifference as the result.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...