Skip to content

Commit 621f25e

Browse files
authored
Create minimum-difference-between-highest-and-lowest-of-k-score.cpp
1 parent 936b62d commit 621f25e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(nlogn)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int minimumDifference(vector<int>& nums, int k) {
7+
sort(begin(nums), end(nums));
8+
int result = numeric_limits<int>::max();
9+
for (int i = k - 1; i < size(nums); ++i) {
10+
result = min(result, nums[i] - nums[i - k + 1]);
11+
}
12+
return result;
13+
}
14+
};

0 commit comments

Comments
 (0)