1431. Kids With the Greatest Number of Candies
#array
Given an integer array, where candies[i]
represents the number of candies the kid has.
Return a boolean array result
of length n
, where result[i]
is true
if post giving the kid all the extraCandies
, they will have the greatest number of candies among all the kids, or false
otherwise.
Intuition
Find the kid with maximum candies & compare with each kid if given extra candies he will have the most or not.
Approach
Iterate over the array to find the kid with maximum candies.
Iterate over the array again to check if
candies[i] + extraCandies
is greater or equal to the kid with maximum candies.
Complexity
Space Complexity
Time Complexity
Only extra space is used to store the result
We itreate over the array only once
Code
Last updated