WTF is this Coding Question??? | Leetcode 875 - Koko Eating Bananas

preview_player
Показать описание
leetcode, coding interview question, data structures, data structures and algorithms, faang
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Here, we are applying binary search to predict the speed of eating. Basic logic is, we divide the no. Of bananas in a pile with the k (middle in this case) which gives us the time consumed to finish that pile. We sum all piles time into hours spent and check if the rate meets the criteria, if we take more time than the guard we move our binary window to a higher range of values ie middle is then bumped up, else we slide the window to a lower range.

sahilmulla
Автор

For those who confused, this is one of divide and conquer basic technique. Since arr[k]=number of bananas ate with speed k is increasing, you can use DC to find minimum k which arr(k) is maximum.

quanghieulee
Автор

Shouldn't the code which changes the left interval upper point be like
if hour_spent <= h:
right = middle - 1 (instead of right = middle as shown ) ?

ajitsdeshpande
Автор

So there are n piles and she has h hours to eat them all by picking 1 pile per hour? So she will only ever eat at most h banana piles. And the speed k should be chosen such that it is the maximum number of bananas in a pile. Right? But even then, if she isnt given enough hours, she wont be able to finish?

rigoluna
Автор

Not sure I get it. Is this a trial and error where you find the best value by halving the range after each try?

yorokobezasshu
visit shbcf.ru