Kids With the Greatest Number of Candies - Problem
There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the i-th kid has, and an integer extraCandies, denoting the number of extra candies that you have.
Return a boolean array result of length n, where result[i] is true if, after giving the i-th kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.
Note that multiple kids can have the greatest number of candies.
Input & Output
Example 1 — Basic Case
$
Input:
candies = [2,3,5,1,3], extraCandies = 3
›
Output:
[true,true,true,false,true]
💡 Note:
Maximum is 5. Kid 0: 2+3=5≥5 ✓, Kid 1: 3+3=6≥5 ✓, Kid 2: 5+3=8≥5 ✓, Kid 3: 1+3=4<5 ✗, Kid 4: 3+3=6≥5 ✓
Example 2 — All Can Be Greatest
$
Input:
candies = [4,2,1,1,2], extraCandies = 1
›
Output:
[true,false,false,false,false]
💡 Note:
Maximum is 4. Only kid 0: 4+1=5≥4 can be greatest. Others: 2+1=3<4, 1+1=2<4
Example 3 — Large Extra Candies
$
Input:
candies = [12,1,12], extraCandies = 10
›
Output:
[true,true,true]
💡 Note:
Maximum is 12. Kid 0: 12+10=22≥12 ✓, Kid 1: 1+10=11<12 ✗, Kid 2: 12+10=22≥12 ✓
Constraints
- 2 ≤ candies.length ≤ 100
- 1 ≤ candies[i] ≤ 100
- 1 ≤ extraCandies ≤ 50
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code