JuniorArray

Kids With the Greatest Number of Candies

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.

Example 1
Inputcandies = [2,3,5,1,3], extraCandies = 3
Output[true,true,true,false,true]
Giving all 3 extra candies to kids 1, 2, 3, and 5 lets each have the greatest number of candies, while kid 4 would not.
Example 2
Inputcandies = [4,2,1,1,2], extraCandies = 1
Output[true,false,false,false,false]
With only 1 extra candy, kid 1 will always have the greatest number of candies even if another kid receives the extra candy.

Constraints

  • n == candies.length
  • 2 <= n <= 100
  • 1 <= candies[i] <= 100
  • 1 <= extraCandies <= 50

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate