More
Blog
Series
Projects
About
Leetcode Practice

LC 875. Koko Eating Bananas

Last updated
March 15, 2024
Reading time
1 min read
  • Back to start


  • 1. Two Sum


  • 2. Add Two Numbers


  • 3. Longest Substring Without Repeating Characters


  • 7. Reverse Integer


  • 9. Palindrome Number


  • 13. Roman to Integer


  • 15. 3Sum


  • 20. Valid Parentheses


  • 22. Generate Parentheses


  • 36. Valid Sudoku


  • 49. Group Anagrams


  • 84. Largest Rectangle in Histogram


  • 88. Merge Sorted Array


  • 125. Valid Palindrome


  • 150. Evaluate Reverse Polish Notation


  • 151. Min Stack


  • 217. Contains Duplicate


  • 238. Product of Array Except Self


  • 242. Valid Anagram


  • 347. Top K Frequent Elements


  • 424. Longest Repeating Character Replacement


  • 496. Next Greater Element I


  • 503. Next Greater Element II


  • 704. Binary Search


  • 739. Daily Temperatures


  • 853. Car Fleet


  • 875. Koko Eating Bananas


  • 901. Online Stock Span


  • 1431. Kids with the Greatest Number of Candies


  • 1475. Final Prices with a Special Discount in a Shop


  • 1832. Check if the Sentence in Pangram


  • 2582. Pass the Pillow

The problem

Solution - O(n∗log(m))O(n * log(m))O(n∗log(m)) Time

function minEatingSpeed(piles: number[], h: number): number {
  let minSpeed = 1
  let maxSpeed = Math.max(...piles)
  while (minSpeed <= maxSpeed) {
    let midSpeed = Math.floor((minSpeed + maxSpeed) / 2)
    let midSpeedHours = piles.reduce((acc, x) => (acc += Math.ceil(x / midSpeed)), 0)
    if (midSpeedHours > h) {
      minSpeed = midSpeed + 1
    } else {
      maxSpeed = midSpeed - 1
    }
  }

  return minSpeed
}
Previous853. Car Fleet
Next901. Online Stock Span
githubfacebookyoutubelinkedintwitter
Hunter Faulkner
•
© 2025
•
Phantom Draught
Yokai icons created by Freepik • Flaticon