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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c4119e77-1261-4d23-93b1-ceb63039984f/Screen_Shot_2021-03-30_at_11.08.46_AM.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4908e3a5-b6a3-4bbe-869d-773532381803/Untitled.png

"""
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)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/233e2659-51ef-47c3-ab08-d3738fe56028/Screen_Shot_2021-03-30_at_11.10.02_AM.png