carsonSgit / leetcode

leetcode grind... doing whatever I can to make sure I'm not bad at CS.
4 stars 0 forks source link

Q1431 #42

Closed carsonSgit closed 3 months ago

carsonSgit commented 3 months ago

What is this problem

There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith 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 ith 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.

How do I solve it

Breakdown:

  1. Save the max value of the array into a variable.
  2. In a for loop, check if the current candies array index value plus the extraCandies is less than or equal to the max.
  3. If it is, a true is added to the list.
  4. Otherwise a false is added.

Resources

None.