Binary Search pattern

Apple Harvest (Koko Eating Bananas)

Given piles of bananas and a fixed number of hours, find the minimum constant eating speed (bananas per hour) that lets you finish all piles within the hour limit. Each hour you eat from a single pile, and if a pile has fewer bananas than your speed you still spend the whole hour on it. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 875
  • 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 875

Medium

From the first idea to the best one

  1. 01 Brute force · try every speed O(n · m)O(1) space
  2. 02 Optimized · binary search the speed O(n log m)O(1) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Apple Harvest (Koko Eating Bananas) and spot the binary search pattern in it
  • Brute force · try every speed: O(n · m) time, O(1) space
  • Optimized · binary search the speed: O(n log m) 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

See Apple Harvest (Koko Eating Bananas) 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.