🔍 Binary Search on probable answer space || Easy solution
IntuitionThe minimum candy a child can get is 1, and the maximum is the largest pile size. We can use binary search on the answer to find the maximum number of
# Intuition
The minimum candy a child can get is 1, and the maximum is the largest pile size. We can use binary search on the answer to find the maximum number of candies that can be allocated to k children.

# Approach
- Binary Search between 1 and max(candies).
- Helper Function counts how many children can get mid candies.
- If childCount >= k, update ans and search right (mid + 1); else, search left (mid - 1).
- Return the maximum feasible candies per child.

# Complexity
- Time complexity:
The binary search runs in O(logM), where M is the maximum candy count.
The helper function $$findChildCount$$ iterates through candies, taking O(N).
Hence, the total complexity is O(NlogM).

- Space complexity: O(1) 

# Code
```cpp []
class Solution {
public:
    long long findChildCount(vector<int>& candies,int candy){
        long long child=0;
        for(int i=0;i<candies.size();i++){
            child+=(candies[i]/candy);
        }
        return child;
    }
    int maximumCandies(vector<int>& candies, long long k) {
        int start=1;
        int end=*(max_element(candies.begin(),candies.end()));
        int ans=0;
        while(start<=end){
            int mid=(start+end)/2;
            //find mid number of candies kitne child ko de sakte h 
            long long childCount=findChildCount(candies,mid);
            if(childCount>=k){
                //matlab itna candy to de sakte h ab max nikalna h to right me jao
                ans=mid;
                start=mid+1;

            }
            else{
                end=mid-1;
            }
        }
        return ans;
    }
};
```
['Array', 'Binary Search', 'C++']