Загрузка...

1984. Minimum Difference Between Highest and Lowest of K Scores | Sliding Window | 25 Jan 2026

LeetCode Daily Problem (25th Jan 2026)

Educational Insight -
The "1984. Minimum Difference Between Highest and Lowest of K Scores" problem reduces to finding the smallest range that covers any k consecutive elements after sorting.

This is a textbook sorted sliding window where for each valid window [i, i+k−1], we compute the range nums[i+k−1] − nums[i] and take the minimum over all such windows.


Key Implementation Details

Sort the scores array nums in ascending order.

Initialize ans = ∞, then for i in range(n−k+1): ans = min(ans, nums[i+k−1] − nums[i]).

Return ans as the minimum achievable difference.


Time: O(n log n) sort + O(n) traversal; space: O(1).

Full platform dropping soon. Stay tuned.
Join the waitlist: https://www.visuallyinclined.in/waitlist

#DSA #LeetCode #Coding #VisuallyInclined

Видео 1984. Minimum Difference Between Highest and Lowest of K Scores | Sliding Window | 25 Jan 2026 канала Visually Inclined
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять