Easy to understand, optimized binary search approach, beginner friendly, detail explained.
\n# Approach\n1. minimum size of candy can be 1,less than 1 can not be possible.\n2. maximum size of candy can be maximum element of given candies array,greater
\n# Approach\n1. minimum size of candy can be 1,less than 1 can not be possible.\n2. maximum size of candy can be maximum element of given candies array,greater than max element can not be possible.\n3. we chose candy size by bianry search, so that we can choose in optimised time.\n4. function func give information about that, candies array\'s element can be divided into mid size.\n5. In function func,\'cnt\' count the nummber of \'mid\' size candy can be divided from candies array elements.\n6. when count of mid size candy greater than our need(k), then we return true, *i.e.*  our answer should be mid but greater than mid can be possible.\n# Complexity\n- Time complexity:$$O(N*logN)$$\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool func(vector<int>&pile,long long h,int mid)\n    {\n        long long cnt=0;\n        for(int i=0;i<pile.size();i++)\n        {\n            cnt += pile[i]/mid ;\n            if(cnt>h)\n            return true;\n        }\n        return cnt>=h;\n    }\n    int maximumCandies(vector<int>& candies, long long k) \n    {\n        int s = 1,e = *max_element(candies.begin(),candies.end());\n        int ans=0;\n        while(s<=e)\n        {\n            int mid = s+ (e-s)/2;\n            if(func(candies,k,mid))\n            {\n                ans = mid;\n                s = mid+1;\n            }\n            else\n            e = mid-1;\n        }\n        return ans;\n    }\n};\n```\n**If you feel this helpful then plz like and upvote this solution \uD83D\uDE0A\nKEEP LEETCODING.............**\n![upvote.png](https://assets.leetcode.com/users/images/2fccf5b3-2212-4efd-afe0-0a5ca0b80d68_1678151551.9504004.png)\n
['Binary Search', 'C++']