Imagine you're a teacher distributing extra candies to kids in your classroom! ๐ญ
You have n kids, each already holding some candies. You're given an integer array candies where candies[i] represents the number of candies the i-th kid currently has.
You also have extraCandies - a stash of bonus candies that you can give to any one kid. Your mission is to determine: "If I give ALL my extra candies to each kid (one at a time), would that kid end up having the most candies in the class?"
Goal: Return a boolean array result of length n, where result[i] is true if giving the i-th kid all the extraCandies makes them have the greatest number of candies among all kids.
Important: Multiple kids can be tied for having the greatest number of candies - that's perfectly fine!
Example: If kids have [2, 3, 5, 1, 3] candies and you have 3 extra candies, then giving all 3 extra candies to kid 0 gives them 2+3=5 candies, which ties for the maximum. So kid 0 would get true in the result!
Input & Output
Visualization
Time & Space Complexity
We make two passes through the array: one to find maximum (O(n)) and one to check each kid (O(n))
Only using constant extra space for storing the maximum value and loop variables
Constraints
- n == candies.length
- 2 โค n โค 100
- 1 โค candies[i] โค 100
- 1 โค extraCandies โค 50