Binary Search pattern
Maximum Candies Allocated to K Children
You have piles of candies and k children. A pile may be split into equal sub-piles, and leftovers are discarded; piles cannot be combined. Find the largest number of candies each child can receive, or 0 if it is impossible. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 2226
- Medium
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Binary SearchLeetCode 2226
Medium
From the first idea to the best one
- 01 Brute force · try every size O(n · max)O(1) space
- 02 Optimized · binary search the answer O(n log max)O(1) space
What you will learn
- How to read Maximum Candies Allocated to K Children and spot the binary search pattern in it
- Brute force · try every size: O(n · max) time, O(1) space
- Optimized · binary search the answer: O(n log max) time, O(1) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Binary Search
- Apple Harvest (Koko Eating Bananas)LC 875 · Medium
- Search in Rotated Sorted ArrayLC 33 · Medium
- Find Minimum in Rotated Sorted ArrayLC 153 · Medium
- Search a 2D MatrixLC 74 · Medium
- Split Array Largest SumLC 410 · Hard
- Kth Smallest in a Sorted MatrixLC 378 · Medium
- Minimum Shipping CapacityLC 1011 · Medium
- OverviewConcept
See Maximum Candies Allocated to K Children run, step by step
Sign in and this page opens on the animation, with all 11 Binary Search problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.