Minimum Difference Between Highest and Lowest of K Scores
EasySliding Windowsliding window
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
nums[i] is the score of student i. Choose exactly k students so that the gap between the highest and lowest chosen score is as small as possible.
Return that minimum possible gap.
Examples
Input: nums = [90], k = 1
Output: 0
With one student, highest and lowest are the same score.
Input: nums = [9,4,1,7], k = 2
Output: 2
Pick 9 and 7 for a gap of 2; no other pair does better.
Constraints
- 1 <= k <= nums.length <= 1000
- 0 <= nums[i] <= 10^5
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.