Koko Eating Bananas | Leetcode 875 Solution | Searching and Sorting
Vložit
- čas přidán 27. 05. 2021
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Question Statement:
1. Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.
2. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.
3. Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.
4. Return the minimum integer k such that she can eat all the bananas within h hours.
Topic: #BinarySearch #leetcode875 #SearchingAndSorting
Used #DataStructure: #Array
#TimeComplexity: O(n*log(M)) , n is array size and M is maximum size of a pile.
#SpaceComplexity: O(1)
For detailed information and other exercises, VISIT: www.pepcoding.com
Have a look at our result: www.pepcoding.com/placements
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
----------------------------------------------------------------
#BinarySearch #geeksforgeeks #SearchingAndSorting #leetcode875
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
Have a look at our result: www.pepcoding.com/placements
Follow us on our CZcams page: / pepcoding
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
Follow us on Pinterest: / _created
Follow us on Twitter: home
.
.
.
Happy Programming !!! Pep it up 😍🤩
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
This girl is a gem. She has gone deep into the problem, unlike many others who seems to have crammed solution and then make videos without understanding concepts.
Hats off to her.
This is pure gold content. Thanks for explaining so well.
Glad you think so!
brilliant explanation.
Mam literally no one can explain in such an easy and elegant way....HATS OFF
Best Explanation compared to other videos of similiar question on youtube. Great.
Manisha Mam ka explanation is pure gold. Never I've walked out from her explanation videos feeling confused. Aap gem ho Mam!🙌🫡
Ma'am your explanation is too good
Mind blowing question
VERY GOOD EXPLANATION, GLAP TO HAVE TEACHERS LIKE U , THANKU SOO MUCH
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like our efforts, we request a review
g.page/Pepcoding/review?rc
You can subscribe to our channel here
czcams.com/users/Pepcodingabout?view_as=subscriber
Best explanation
Thank You. Great Explanation!
Simply superb explanation, thanks!!
love u ma'am .You are the best.
Best Explanation
hats off to the way you teach . Thankyou :)
It's my pleasure
great explanation loved it
what an explanation 👏👏👏 best video explanation for this question. Thank you !
Glad it was helpful!
Keep learning.
And for better experience, visit nados.io, where you will get well curated content and career opportunities.
brilliant explanation ::
Your explaination is brilliant. Best tutorial on the internet
For more of her content do check nados.pepcoding.com
Very good
I request to pep coding to upload a video in which Mam tell us little bit about herself and her coding journey
Please
Thanks a lot mam, for most amazing explanation with deep insight. Mam is there any calculation possible such that we can calculate min_speed val,? as it would be atleast 1 & atmost max in piles.
Thanks Mam :-)
amazing explanation ever...the way u explain is really superb.
Glad you liked it!
For better experience, visit nados.pepcoding.com, where you will get well curated content and career opportunities.
thank you :)
Keep learning, Keep growing and keep loving Pepcoding!😊
wow
great explanation
Glad it was helpful! Keep learning, Keep growing and keep loving Pepcoding!😊
thanx di for this wonderful solution
Keep learning.
For better experience, visit nados.io, where you will get well curated content and career opportunities.
Mam, you are the best teacher :)
Thankyou!
Keep learning.
And for better experience, visit nados.io, where you will get well curated content and career opportunities.
i do the same but is give me 5 but ans is 4 for that test case Input: piles = [3,6,7,11], h = 18
Output: 2 and my solution is
class Solution {
private static boolean isPossibleToEat(int[] arr, int speed, int h) {
int time = 0;
for (int i = 0; i < arr.length; i++) {
time += (int) Math.ceil(arr[i] * 1.0 / speed);
}
return time
dude, I'm solving this question for 1 hour and just saw the tag easy on your platform seriously? this question is just similar as allocation of pages in students from gfg which is hard level..
great explanation , production level code !
Glad it helped! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
class Solution {
public int minEatingSpeed(int[] piles, int h) {
int max = 0;
for(int val : piles){
max = Math.max(val, max);
}
if(h == piles.length){
return max;
}
int lo = 1;
int hi = max;
int ans = 0;
while(lo total hours
for(int bananas : piles){
th += Math.ceil((bananas * 1.0) / speed);
}
return th
The code is good but has an exception of zero division error so consider that also.. But overall it passed most of the cases
for better insight you can visit nados.io
Thanks for the video . 1 doubt tha min speed start mei 0 assume ki hai hum uss speed ko given array k min value kyu ni rkh skte?
[2,2,2] and hours=10.. if we put low = min(of array) then ans would be 2 but actually we can even eat banana at speed of 1 banana per hour
@@mudrad1930 👍
description me iski complexity nlogm di ha where m is maximum size of pile nlogn nhi honi chahiye ????
madam ji is question ne hamari watt laga di 2 ghanta le lia hamra lekin lower bound ko 1 se initialize karne se hi pass hua ye leetcode par !!!
What will be the complexity?
O(logn)
@@neerajpandey8159 O(nlogn) hoga
ma'am leetcode cases r not being passed using ur code.. pls check once over thr
make low =1 instead 0.
@@kalyanchowdhury2240 Thank you! Can you please tell why this works, and what's wrong with low =0?
@@adityasangani4156 speed cant be 0
Pep coding is not focusing to solve the questions....they will be focusing to clear the concept and theory.....Inke jaisa CZcams par koi nahi......kuchh do chaar ko chhodkar...
thoda lenghty kar diya code , yeh aur easily explainable hai aur kam lines me bhi ho jayega
mam aggresive cow bhi kara do
Mam I think "lo" ko agar piles array ke minimum pe rakhege toh code thoda aur optimize ho skta h.. lo ko 0 se start krne ki zarurat nhi h shayad..
it will fail for test case
[6] , h = 6
ONE TEST CASE FAILED
Input:
[805306368,805306368,805306368]
1000000000
Output:
1
Expected:
3
Replace your Math.ceil statement to this and this test case would pass
m += Math.ceil((double)piles[i] / (double)mid);