Kids With the Greatest Number of Candies - LeetCode
Given the array candies
and the integer extraCandies
, where candies[i]
represents the number of candies that the ith kid has.
For each kid check if there is a way to distribute extraCandies
among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of candies.
"""
1431. Kids With the Greatest Number of Candies
Given the array candies and the integer extraCandies,
where candies[i] represents the number of candies that the ith kid has.
For each kid check if there is a way to distribute extraCandies among the kids
such that he or she can have the greatest number of candies among them.
Notice that multiple kids can have the greatest number of candies.
= finds if there are extra candies can she/he have the greatest number of candies.
Input: candies = [2,3,5,1,3], extraCandies = 3
Output: [true,true,true,false,true]
"""
candies = [2,3,5,1,3]
extraCandies = 3
maximum = candies[0]
i = 1
while i < len(candies):
if candies[i] > maximum:
maximum = candies[i]
i += 1
i = 0
while i < len(candies):
if candies[i] + extraCandies >= maximum:
candies[i] = "true"
else:
candies[i] = "false"
i += 1
print(candies)