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
candies = [2,3,5,1,3], extraCandies = 3[true,true,true,false,true]Maximum candies is 5. Kid 0: 2+3=5 >= 5 (true). Kid 1: 3+3=6 >= 5 (true). Kid 2: 5+3=8 >= 5 (true). Kid 3: 1+3=4 < 5 (false). Kid 4: 3+3=6 >= 5 (true).
candies = [1,1,1,1,1], extraCandies = 2[true,true,true,true,true]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.
candies = [10,8,12,6], extraCandies = 1[false,false,true,false]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