Search
 
SCRIPT & CODE EXAMPLE
 

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

PREVIOUS NEXT
Code Example
Python :: use python logging to log user ips+time in a file whenever a request comes to the server, this should be done in a custom middleware. 
Python :: save media file from url python 
Python :: how to sort a list of lists in reverse order using the first parameter in python 
Python :: csv file python 
Python :: import all files on the same directory python 
Python :: heapq basic push and pop - default minHeap 
Python :: split dataset folders in train test valid using python 
Python :: Count the number of Missing Values in the DataFrame 
Python :: python write multiline string to file 
Python :: Python Tkinter RadioButton Widget Syntax 
Python :: login() takes 1 positional argument but 2 were given 
Python :: design patterns python - restrict what methods of the wrapped class to expose 
Python :: csrf is not detected using sendbeacon django 
Python :: get column means pandas 
Python :: how to fix value error in model.fit 
Python :: how to strip characters in python 
Python :: python convert string object to int object 
Python :: Reading Excel and other Microsoft Office files 
Python :: python script to open google chrome 
Python :: how to unpack in python 
Python :: djangorestframework install command 
Python :: python Access both key and value using iteritems() 
Python :: online python pseudo code writer python 
Python :: frontmost flag qt 
Python :: reassign variable python 
Python :: get resource path python 
Python :: can 2020 get any worse 
Python :: how to sum a column in csv python using list in python 
Python :: CNN Libraries 
Python :: iloc[ ] slicing 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =