Skip to content

Commit 1be1669

Browse files
solves minimum difference betweeb highest and lowest of k scores
1 parent d372e5e commit 1be1669

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@
475475
| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | |
476476
| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | |
477477
| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | |
478-
| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | | |
478+
| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | |
479479
| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | | |
480480
| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | | |
481481
| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores
2+
// T: O(Nlog(N))
3+
// S: O(1)
4+
5+
import java.util.Arrays;
6+
7+
public class MinimumDifferenceBetweenHighestAndLowestOfKScores {
8+
public int minimumDifference(int[] nums, int k) {
9+
Arrays.sort(nums);
10+
int minDifference = Integer.MAX_VALUE;
11+
for (int i = 0 ; i < nums.length - k + 1 ; i++) {
12+
minDifference = Math.min(minDifference, nums[i + k - 1] - nums[i]);
13+
}
14+
return minDifference;
15+
}
16+
}

0 commit comments

Comments
 (0)