Easy To Understand Python Solution (Binary Search)
\nclass Solution:\n    def maximumCandies(self, candies, k):\n        n = len(candies)\n        left = 1  # the least number of candy in each stack we can give 
```\nclass Solution:\n    def maximumCandies(self, candies, k):\n        n = len(candies)\n        left = 1  # the least number of candy in each stack we can give to each student is one\n        right = max(candies)  # the max number of candy in each stack that we can give to each student is the maximum number in the candies array\n        ans = 0 # ans here is used to store the maximum amount in each stack that we can give to each children. \n               # If we don\'t have enough to distribute, we will return 0 at the end so we initialize it to be 0 now.\n\n        while left <= right:  # binary search\n            numberOfPiles = 0\n            mid = (left) + (right - left) // 2  # the number of candies we require to form a stack\n\n            for i in range(n):   # loop through the array to find the numbers of stack we can form\n                numberOfPiles += candies[i] // mid   # we add to the numberOfPiles whenever we find that this current stack (candies[i]) can be split into mid (the number of candies we require to form a stack)\n\n            if numberOfPiles >= k: # if our number of piles is greater or equal than the students we have, so we have enough to distribute\n                ans = max(ans, mid)   # we first store the max no. of candies in each stack that we can give to each student \n                left = mid + 1      # we will try to increase the number of candies in each stack that we can give to each student\n            else: \n                right = mid - 1   # we will try to reduce the number of candies in each stack that we can give to each student\n        return ans\n```\n
['Binary Search', 'Binary Tree', 'Python', 'Python3']