Determine which kids can end up with the greatest number of candies after receiving extra candies.
Problem
You are given an array candies, where candies[i] is the number of candies the -th kid has, and an integer extraCandies.
For each kid, decide whether that kid could have the greatest number of candies among all kids after receiving all of the extra candies. The extra candies can be given entirely to any one kid.
Return a list of boolean values where the -th value is true if the -th kid can have the greatest number of candies after receiving extraCandies, otherwise false.
A kid is considered to have the greatest number of candies if their candy count is at least as large as every other kid's candy count.
Input Format
candies: an array of integersextraCandies: an integer
The input represents one test case.
Output Format
- Return a boolean array of the same length as
candies. - Each entry indicates whether that kid can reach the maximum candy count after receiving all extra candies.
Constraints
- The array contains at least one kid.
- Candy counts and extra candies are non-negative integers.
- Typical solution should run in linear time.
Example 1
Input
candies = [2,3,5,1,3], extraCandies = 3
Output
[true,true,true,false,true]
Explanation
If a kid receives 3 extra candies, their final count becomes [5,6,8,4,6]. Kids 0, 1, 2, and 4 can reach at least the maximum count of the original group.
Example 2
Input
candies = [4,2,1,1,2], extraCandies = 1
Output
[true,false,false,false,false]
Explanation
The maximum current count is 4. Only the first kid can still have the greatest number after receiving 1 extra candy.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.