 All Problems
Minimum Difference Between Highest and Lowest of K Scores
easy
arrays
sorting
sliding window
amazon
google

Given a 0-indexed integer array nums and a positive integer k, choose any k elements and return the minimum possible difference between the maximum and minimum chosen values.

Example 1:

Input: 90
k: 1
Output: 0

Example 2:

Input: 9 4 1 7
k: 2
Output: 2

Input format: Line 1: space-separated scores. Line 2: k.

Output format: Minimum difference.

Run to check your code against the sample cases, or submit to run every case