Kids With the Greatest Number of Candies

Easy

Description

Given the array candies and the integer extraCandies, return a boolean array result where result[i] is true if, after giving child i all extra candies, they will have the greatest number of candies.

Examples

Input:candies = [2,3,5,1,3], extraCandies = 3
Output:[true,true,true,false,true]
Explanation:

Check each kid.

Input:candies = [1,1,1,1,1], extraCandies = 2
Output:[true,true,true,true,true]
Explanation:

All kids start with equal candies (1 each). The maximum is 1, so giving any kid 2 extra candies results in 3, which is greater than or equal to the maximum (1). Therefore, every kid can have the greatest number of candies.

Input:candies = [10,8,12,6], extraCandies = 1
Output:[false,false,true,false]
Explanation:

The maximum number of candies is 12 (third kid). Kid 1: 10+1=11 < 12 (false), Kid 2: 8+1=9 < 12 (false), Kid 3: 12+1=13 ≥ 12 (true), Kid 4: 6+1=7 < 12 (false). Only the kid who already has the most candies can maintain the greatest number.

Constraints

  • 2 ≤ n ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!