C++ || Binary Search on Search Space || Easy Solution
Time Complexity : O(n*logm) , where m is the maximum number of candies in the single pile.\n\nclass Solution {\nprivate:\n    bool isValid(vector<int>& candies,
**Time Complexity : O(n*logm)** , where m is the maximum number of candies in the single pile.\n```\nclass Solution {\nprivate:\n    bool isValid(vector<int>& candies, long long k, int max_candies){\n        long long child_cnt = 0;\n        \n        for(auto candies: candies)\n            child_cnt += candies/max_candies;\n        \n        return child_cnt >= k;\n    }\npublic:\n    int maximumCandies(vector<int>& candies, long long k) {\n        int start = 1;\n        int end = *max_element(candies.begin(), candies.end());\n        int res = 0;\n\t\t\n        while(start <= end){\n            int mid = start+(end-start)/2;\n            if(isValid(candies, k, mid)){\n                res = mid;\n                start = mid+1;\n            }\n            else\n                end = mid-1;\n        }\n        \n        return res;\n    }\n};\n```\nUpvote if this helps.\nThanks!
['C', 'Binary Tree', 'C++']