Skip to content

Commit 183fd89

Browse files
committed
Add solution #1431
1 parent 7093a36 commit 183fd89

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
1402|[Reducing Dishes](./1402-reducing-dishes.js)|Hard|
180180
1408|[String Matching in an Array](./1408-string-matching-in-an-array.js)|Easy|
181181
1410|[HTML Entity Parser](./1410-html-entity-parser.js)|Medium|
182+
1431|[Kids With the Greatest Number of Candies](./1431-kids-with-the-greatest-number-of-candies.js)|Easy|
182183
1436|[Destination City](./1436-destination-city.js)|Easy|
183184
1437|[Check If All 1's Are at Least Length K Places Away](./1437-check-if-all-1s-are-at-least-length-k-places-away.js)|Easy|
184185
1446|[Consecutive Characters](./1446-consecutive-characters.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1431. Kids With the Greatest Number of Candies
3+
* https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
4+
* Difficulty: Easy
5+
*
6+
* There are n kids with candies. You are given an integer array candies, where each
7+
* candies[i] represents the number of candies the ith kid has, and an integer
8+
* extraCandies, denoting the number of extra candies that you have.
9+
*
10+
* Return a boolean array result of length n, where result[i] is true if, after giving
11+
* the ith kid all the extraCandies, they will have the greatest number of candies
12+
* among all the kids, or false otherwise.
13+
*
14+
* Note that multiple kids can have the greatest number of candies.
15+
*/
16+
17+
/**
18+
* @param {number[]} candies
19+
* @param {number} extraCandies
20+
* @return {boolean[]}
21+
*/
22+
var kidsWithCandies = function(candies, extraCandies) {
23+
const max = Math.max(...candies);
24+
return candies.map(count => count + extraCandies >= max);
25+
};

0 commit comments

Comments
 (0)