Koko Eating Bananas - (Leetcode - 875) - (Google, Microsoft) : Explanation ➕ Live Coding

Sdílet
Vložit
  • čas přidán 6. 03. 2023
  • This is the 11th Video on our Binary Search Playlist.
    In this video we will try to solve a very easy but interesting Binary Search problem "Koko Eating Bananas" (Leetcode-875).
    Problem Name : Koko Eating Bananas
    Company Tags : Google, Microsoft
    My solutions on Github : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/koko-ea...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
    #interviewpreparation #interview_ds_algo #hinglish

Komentáře • 41

  • @vinayjoshi8714
    @vinayjoshi8714 Před měsícem +1

    Bhaiya bus waali problem samjhne ke baad yeh wala khud se kar paya mein thank you bhaiya 🥰

  • @souravjoshi2293
    @souravjoshi2293 Před rokem +10

    I feel like am I growing with you bro.
    Solved because of your Binary Search playlist. You have come to us like a boon

  • @shreyasrivastava368
    @shreyasrivastava368 Před rokem +19

    Please continue the graph concept series also🙂

  • @riyazsayyad4047
    @riyazsayyad4047 Před rokem +5

    Happy to solve it by myself because of yesterday's explanation, thank you soo much

  • @devanshu2755
    @devanshu2755 Před rokem +4

    bro best again that's all. even today i dont searched by name on youtube i just arrived to your channel.

  • @tutuimam3381
    @tutuimam3381 Před rokem +3

    Amazing explanation 🌹

  • @Rajat_maurya
    @Rajat_maurya Před rokem +3

    Bhai huge respect aj holi k din bhi app videos bana rahe❤

  • @itspravas
    @itspravas Před rokem +3

    You can do the for loop in one line. 👍
    actualHours += celi(x/mid)
    OR
    actualHours += (x + mid - 1) / mid;
    OR
    actualHours = 1 + ((x - 1) / mid); // if x != 0

  • @Thriftinghai
    @Thriftinghai Před 11 měsíci +1

    binge watching this whole playlist. Loved it

  • @SANDALAGRAWALBAI
    @SANDALAGRAWALBAI Před rokem +2

    Awesome!!!

  • @YashSinghal
    @YashSinghal Před rokem +6

    same as yesterday only difference at 20:13

  • @rishichaurasia8635
    @rishichaurasia8635 Před 8 měsíci

    Bahut badhiya aapane samjhaya hai

  • @akshaychavan5511
    @akshaychavan5511 Před 4 měsíci

    Attempted after watching your approach -
    def canEatInHours(self, piles, k, hours):
    count = 0
    for bananas in piles:
    count+=ceil(bananas/k)
    return count int:
    low, high = 1, max(piles)
    optimalMid = high
    while low

  • @TheCurrencyNomad1
    @TheCurrencyNomad1 Před 6 měsíci

    Meri Jaan mjaaa aa gya yaarrr Explanation me.
    Is concept ko shyd "Binary Search Over Answer" bolte hain, maine khi pdha tha pehle lkn tb smjh ni aaya tha.Aaj aapki video se smjh aaya.
    Thanks Bawa and God bless you.

  • @technologicalvivek7510
    @technologicalvivek7510 Před 4 měsíci +1

    Bhaiya aap ko kaise pta ki koko she hi hai mazak kar raha.
    But aapne aacha samajhaya question pure intutiton se line by line.
    Depth concept hai or important bhi .Isliye aapse samjha mene.

  • @Animesh_SGIS
    @Animesh_SGIS Před rokem

    Why are we using l < r rather than l

  • @techyou6163
    @techyou6163 Před 4 měsíci

    can we use ceil value instead of dividing then taking modules
    please reply??

  • @B-Billy
    @B-Billy Před 21 dnem +1

    Thanks for the video. It is so good.
    I just have one query : When we know that koko can eat mid number of Bananas, why are we setting our right pointer to mid and not 'mid-1'? I tried setting it to mid-1 but ofcourse it does not work. I know that in binary search we set mid-1 and mid+1, tried using same intuition here.
    Can you please explain why we are not setting r to mid-1 and why it does not work.

    • @B-Billy
      @B-Billy Před 21 dnem

      I got the issue.
      The issue is not with setting r to mid -1. The issue is that we are using 'int' to calculate the totalHoursRequiredToEatBanana. There is a test case - if you eat 1 banana so eventually will endup adding all the piles' element which will go out of 'int' limit and it will give 'true' because negatve value will always be less than h. So I used 'long' and it worked.
      Test Case : {805306368,805306368,805306368}, k = 1000000000

    • @codestorywithMIK
      @codestorywithMIK  Před 21 dnem

      Because here in problems based on “Binart Search On Answer” , we never skip mid value, because mid can also be a possible answer for our problem.

  • @shloksuman8164
    @shloksuman8164 Před rokem +1

    exactly , like yesterday's logic

  • @manauwarzulfekaransari4719
    @manauwarzulfekaransari4719 Před 4 měsíci +1

    Here is the javascript code for the above problem
    var minEatingSpeed = function(piles, h) {
    let l = 1;
    let r = Math.max(...piles);
    while(l < r){
    let m = Math.floor(l + (r-l)/2);
    let x = piles.reduce((acc,curr) => {
    return acc + Math.ceil(curr/m);
    },0);
    if(x

  • @devnn10
    @devnn10 Před 4 měsíci

    konsa tha yesterday wla ? pls btado

  • @vedanshgaur9517
    @vedanshgaur9517 Před rokem +1

    EASY++;

  • @easyvedicmaths886
    @easyvedicmaths886 Před měsícem

    how one will get to know ke it is binary search question, or it can be solved by two pointers or stack or it can be solved by BFS or dp? ..cause there are many questions where you need to find "minimum" ?

    • @Rahul_Mongia
      @Rahul_Mongia Před měsícem

      when a ceratain range gives u a vakid ans , and after a point it dont satisfy , we use BS.

  • @035-harshitsingh7
    @035-harshitsingh7 Před rokem +2

    bhaiya ye r==mid kyun kiya hai r=mid-1 kyun nhi kiya hm poore right half ko ignore kyun nhi kr de rhe?i always get confuse over here.

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      Because if you notice, that mid was a valid value (could eat all bananas in time

    • @035-harshitsingh7
      @035-harshitsingh7 Před rokem

      @@codestorywithMIK okay bhaiya i get it.Thanks a lot✌

  • @devanshu2755
    @devanshu2755 Před rokem +1

    bro ek question he maximum product subarray uski vedio he to link share karo nhi to please solve it

  • @DeepakSingh-fd2ix
    @DeepakSingh-fd2ix Před rokem

    Sir brute force ka code bhi smjaao

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      For brute force , you can start from maximum banana that can be eaten and then check for each time. If the value works fine, then decrement it and keep checking until you get the optimal one.
      Code below :
      class Solution {
      public:
      int minEatingSpeed(vector& piles, int h) {
      int per_hour_banana = *max_element(begin(piles), end(piles));
      while (per_hour_banana > 0) {
      int count = 0;
      for (int pile : piles) {
      count += pile/per_hour_banana;
      if(pile%per_hour_banana != 0)
      count++;
      if (count > h)
      return per_hour_banana + 1;
      }
      per_hour_banana--;
      }
      return 0;
      }
      };

  • @satyasanjay1339
    @satyasanjay1339 Před rokem +1

    I was also able to solve this problem myself.😀😀
    Java Code:
    class Solution {
    boolean canEatAllBananas(int[] piles, int speed, int target_hour){
    int req_hour = 0;
    for(int i = 0; i < piles.length; i++){
    req_hour += Math.ceil(piles[i]*1.0/speed*1.0);
    }
    return req_hour