Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4bd6143

Browse files
committed
Add solution #1984
1 parent 7693c48 commit 4bd6143

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,669 LeetCode solutions in JavaScript
1+
# 1,670 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1522,6 +1522,7 @@
15221522
1980|[Find Unique Binary String](./solutions/1980-find-unique-binary-string.js)|Medium|
15231523
1981|[Minimize the Difference Between Target and Chosen Elements](./solutions/1981-minimize-the-difference-between-target-and-chosen-elements.js)|Medium|
15241524
1982|[Find Array Given Subset Sums](./solutions/1982-find-array-given-subset-sums.js)|Hard|
1525+
1984|[Minimum Difference Between Highest and Lowest of K Scores](./solutions/1984-minimum-difference-between-highest-and-lowest-of-k-scores.js)|Easy|
15251526
1985|[Find the Kth Largest Integer in the Array](./solutions/1985-find-the-kth-largest-integer-in-the-array.js)|Medium|
15261527
1996|[The Number of Weak Characters in the Game](./solutions/1996-the-number-of-weak-characters-in-the-game.js)|Medium|
15271528
2000|[Reverse Prefix of Word](./solutions/2000-reverse-prefix-of-word.js)|Easy|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 1984. Minimum Difference Between Highest and Lowest of K Scores
3+
* https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/
4+
* Difficulty: Easy
5+
*
6+
* You are given a 0-indexed integer array nums, where nums[i] represents the score of the
7+
* ith student. You are also given an integer k.
8+
*
9+
* Pick the scores of any k students from the array so that the difference between the highest
10+
* and the lowest of the k scores is minimized.
11+
*
12+
* Return the minimum possible difference.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @param {number} k
18+
* @return {number}
19+
*/
20+
var minimumDifference = function(nums, k) {
21+
nums.sort((a, b) => a - b);
22+
let result = Infinity;
23+
24+
for (let i = 0; i <= nums.length - k; i++) {
25+
result = Math.min(result, nums[i + k - 1] - nums[i]);
26+
}
27+
28+
return result;
29+
};

0 commit comments

Comments
 (0)