Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
LeetCode 875 – Koko Eating Bananas | Binary Search on Answer (C++)
Play lesson

LeetCode 75 C++ | Step-by-Step Solutions (LAN Academy) - LeetCode 875 – Koko Eating Bananas | Binary Search on Answer (C++)

4.0 (1)
12 learners

What you'll learn

This course includes

  • 5.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

In this video we solve LeetCode 875 – "Koko Eating Bananas" using a classic Binary Search on Answer approach in C++. Koko wants to finish all banana piles in at most h hours. Instead of guessing the speed k randomly, we search for the minimum eating speed between 1 and max(piles), and use binary search to find the smallest k such that she can finish on time. Key ideas: β€’ The faster Koko eats, the fewer hours she needs β†’ monotonic condition β€’ For a given speed k, we can compute how many hours she needs: hours = sum(ceil(pile / k)) over all piles β€’ We binary search the answer k in [1, max(piles)] and check this condition Time complexity: β€’ O(n log M), where M = max(piles) What you’ll see in this video: β€’ Problem explanation and examples β€’ Intuition for "binary search on answer" β€’ Implementation of the check function (canFinish) β€’ Step-by-step C++ solution β€’ Complexity analysis and quick recap If this video helps you, please LIKE, SUBSCRIBE and check the rest of my LeetCode playlist! If this video helped you, please: πŸ‘ Like the video πŸ’¬ Leave a comment with your solution or questions πŸ”” Subscribe for more LeetCode & algorithm walkthroughs –––––––––––––––– LAN Academy – Learn Algorithms & Programming 🌐 Website: https://lanacademy-school.thinkific.com πŸ“Ί YouTube: @lanacademy9521 🐦 Twitter: https://x.com/SolutionsLan #cplusplus #binarysearch #dsa #programming #leetcode #leetcode875 #binarysearch #koko #cpp #codinginterview #leetcode #leetcodecoding #leetcodesolution #leetcodechallenge #faang #fang #computerscience #cs #codingtiktok #coding #codinglife #boostofhope #fyp #codinginterview #softwareengineer #swe #tech #foryou #python #learntocode #google #techtok #programming #algorithms #learntocode @reper #foryou #viral #reper #urmaritori #for

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

FAQs

Course Hive
Download CourseHive
Keep learning anywhere