🚀Simple Python Solution | Binary Search Approach 💡  
IntuitionWe need to distribute candies as evenly as possible among k children while maximizing the number of candies each child gets. Since we are dividing cand
# Intuition
We need to distribute candies as evenly as possible among k children while maximizing the number of candies each child gets. Since we are dividing candies from different piles, we can use binary search to efficiently find the maximum number of candies each child can receive.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
1. Binary Search on Maximum Candies Per Child:

- Initialize l = 1 and r = max_value (largest pile).
- Use binary search to find the highest possible needed_piles that allows at least k children to get candies.

2. Check Feasibility (candies_distribution_possible):
- Compute total_piles = sum(candie // needed_piles for candie in candies).
- If total_piles >= k, update max_candies and increase l. Otherwise, decrease r.

3. Return max_candies.

# Complexity
- Time complexity: O(nlogm)
- n is the number of piles, and m is the maximum candies in any pile.
- Binary search runs in 𝑂(log 𝑚), and for each mid, we check O(n).
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
- We use only a few extra variables, so space usage is constant.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maximumCandies(self, candies: List[int], k: int) -> int:
        max_value=max(candies)

        def candies_distribution_possible(needed_piles):
            total_piles=0
            for candie in candies:
                total_piles+=(candie//needed_piles)
            
            return True if total_piles>=k else False

        def binary_search(max_value):
            l=1
            r=max_value
            max_candies=0
            while l<=r:
                
                mid=(r-l)//2+l

                if mid>0 and candies_distribution_possible(mid):
                    max_candies=mid
                    l=mid+1

                else:
                    r=mid-1


            return max_candies
        
        return binary_search(max_value)
        

            


```
['Binary Search', 'Python3']