#448 Minimum Difference Among k Numbers

Companies:
T-Bank
Themes:
AlgorithmsSortingPractice

An array of natural numbers is given; numbers may repeat. Select k numbers so that the difference between the maximum and minimum selected values is minimal. Return this difference.

Input: [10, 100, 300, 200, 1000, 20, 30], k = 3
Output: 20

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in