623/670

623. Kids With the Greatest Number of Candies

Easy

A row of kids each holds some candies: candies[i] is how many the i-th kid has. You also have a bonus of extraCandies that could be handed, in full, to any one kid.

Your function receives the integer array candies and the integer extraCandies, and must return a list of booleans of the same length, where entry i is true exactly when giving the whole bonus to kid i would leave that kid with at least as many candies as anyone else in the row. Ties are enough — the kid only has to match the current maximum, not beat it.

Each entry is an independent thought experiment: evaluate kid i as if they alone received all the extra candies, with everyone else unchanged.

Example 1:

Input: candies = [2, 3, 5, 1, 3], extraCandies = 3

Output: [true, true, true, false, true]

Explanation: The current maximum is 5. Boosted totals are 5, 6, 8, 4, 6 — every kid reaches 5 except kid 3, whose 1 + 3 = 4 falls short.

Example 2:

Input: candies = [4, 2, 1, 1, 2], extraCandies = 1

Output: [true, false, false, false, false]

Explanation: The maximum is 4. Only kid 0 (4 + 1 = 5) reaches it; every other kid tops out at 3 or less.

Example 3:

Input: candies = [12, 1, 12], extraCandies = 10

Output: [true, false, true]

Explanation: Kids 0 and 2 already hold the maximum of 12, so any bonus keeps them on top. Kid 1 reaches only 11.

Constraints:

  • 2 ≤ candies.length ≤ 100
  • 1 ≤ candies[i] ≤ 100
  • 1 ≤ extraCandies ≤ 50

Hints:

Kid i ends up with candies[i] + extraCandies. What single number do they have to reach?

Every kid is compared against the same target: the maximum of the original array. Compute it once, then answer each kid with one comparison.

▶ Run checks these sample cases. Submit also runs hidden edge cases.

Input: candies = [2, 3, 5, 1, 3], extraCandies = 3

Expected output: [true, true, true, false, true]