Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Distribute Candy Algorithm Python

class Solution(object):
   def distributeCandies(self, candies, num_people):
      res = [0 for i in range(num_people)]
      index = 0
      while candies>0:
         res[index%num_people] += min(candies,index+1)
         candies-=(index+1)
         index+=1
      return res
ob1 = Solution()
print(ob1.distributeCandies(8, 3))
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #Distribute #Candy #Algorithm #Python
ADD COMMENT
Topic
Name
2+4 =