You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Problem Name: Kids With the Greatest Number of Candies
7
+
##===================================
8
+
#
9
+
#Given the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has.
10
+
#
11
+
#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.
12
+
#
13
+
#Example 1:
14
+
#
15
+
#Input: candies = [2,3,5,1,3], extraCandies = 3
16
+
#Output: [true,true,true,false,true]
17
+
#Explanation:
18
+
#Kid 1 has 2 candies and if he or she receives all extra candies (3) will have 5 candies --- the greatest number of candies among the kids.
19
+
#Kid 2 has 3 candies and if he or she receives at least 2 extra candies will have the greatest number of candies among the kids.
20
+
#Kid 3 has 5 candies and this is already the greatest number of candies among the kids.
21
+
#Kid 4 has 1 candy and even if he or she receives all extra candies will only have 4 candies.
22
+
#Kid 5 has 3 candies and if he or she receives at least 2 extra candies will have the greatest number of candies among the kids.
23
+
#Example 2:
24
+
#
25
+
#Input: candies = [4,2,1,1,2], extraCandies = 1
26
+
#Output: [true,false,false,false,false]
27
+
#Explanation: There is only 1 extra candy, therefore only kid 1 will have the greatest number of candies among the kids regardless of who takes the extra candy.
28
+
#Example 3:
29
+
#
30
+
#Input: candies = [12,1,12], extraCandies = 10
31
+
#Output: [true,false,true]
32
+
classSolution:
33
+
defkidsWithCandies(self, candies, extraCandies):
34
+
tmpMax=max(candies) #Initialize tmpMax that finds the max number of candies
35
+
tmp= [0]*len(candies) #Initialize tmp list which has same length as candies having zero value
36
+
true, false=True, False#Initialize true and false variables
37
+
foriinrange(len(candies)): #Loop through candies
38
+
ifcandies[i] +extraCandies>=tmpMax: #Condition-check: If candies[i] and extraCandies sum has more than or same as tmpMax
39
+
tmp[i] =true#Then we update our tmp list by adding value true
40
+
else: #Condition-check: Else
41
+
tmp[i] =false#Otherwise update tmp list by adding value false
0 commit comments