Trapping Rain Water | without stack | Made Super Easy | Leetcode 42 | codestorywithMIK

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 52

  • @abhayshukla322
    @abhayshukla322 Рік тому +13

    Thank you so much bhai mai yeh video dekhne se pehle khud bhi try kiya tha to solve but I am not able to figure out that. Although aapka video dekhne se ekdum clear ho gya hai jo aapne small example lekr samjhaya hai na wo toh jbardast tha

  • @anubhavbhutani8512
    @anubhavbhutani8512 3 місяці тому +3

    Currently at 4:26 , Stopped the video, tried it by myself and boom done! Thank you so much Mik!

  • @EB-ot8uu
    @EB-ot8uu 9 місяців тому +10

    I completed your arrays playlist 2 days ago binge watched all of them. today solved this on my own. thanks a lot

    • @Aniket_0314
      @Aniket_0314 7 місяців тому

      which is his arrays playlist? I only found this one? Can you show me the playlist you're talking about?
      Thanks

  • @FanIQQuiz
    @FanIQQuiz Рік тому +5

    This channel is a blessing. What a fine explanation.

  • @aggarwalsachin4854
    @aggarwalsachin4854 9 місяців тому +3

    bro, you just killed it

  • @raushankumargupta7018
    @raushankumargupta7018 9 місяців тому +2

    Aapka explanation boht hi easy & top quality hota h hmesa. Thank you very much bhai. Happy Eid🎉

  • @wearevacationuncoverers
    @wearevacationuncoverers 9 місяців тому +2

    Congratulations in advance for 41K. your channel will blast and will reach soon to 1M

  • @aws_handles
    @aws_handles 9 місяців тому +8

    the legend is here

  • @mohdmehraj4546
    @mohdmehraj4546 4 місяці тому +3

    I was Expecting O(1) space By seeing the thumbnail !!

  • @gui-codes
    @gui-codes 9 місяців тому

    mind blowing. i now comment on every video of yours because you are too good man

  • @opsahadat9567
    @opsahadat9567 10 місяців тому +4

    OMG, ITS SOMTING HERD FOR ME, BUT FINALLY DONE 💜💜

  • @MohdDanish-j7p
    @MohdDanish-j7p Рік тому +1

    what a fabulous explanation..

  • @vivekgupta_3085
    @vivekgupta_3085 9 місяців тому +1

    Good approach brother thank you

  • @ankitajha3962
    @ankitajha3962 5 місяців тому

    I was able to code on my own (: Great explanation

  • @anmolverma075
    @anmolverma075 5 місяців тому

    Sir what an amazing and simple explaination!
    Thanks a lot!

  • @priyanshpal5070
    @priyanshpal5070 9 місяців тому +1

    just earned a sub bro, keep up the good work

  • @SamriddhiSharma-xc6iw
    @SamriddhiSharma-xc6iw 6 місяців тому

    Bhaiya please make a video for leetcode problem 394 , "Decode String". It will be a great help. And thanks a lot for such easy and explanatory videos.

  • @saanchit1
    @saanchit1 8 місяців тому +1

    @codestorywithMIK I love the work you are doing, for this question I think you could have added the optimised solution (2 pointer) as it's space complexity is o(n)

    • @codestorywithMIK
      @codestorywithMIK  8 місяців тому +1

      Appreciate your kind words Saanchit.
      I agree, I should have added. Actually this us an old video, I will try to create a separate video covering the 2 pointer solution ❤️❤️

  • @akbar55555shaikh
    @akbar55555shaikh 9 місяців тому

    Now I feel, this problem should be marked as easy on leetcode 😊.

  • @thefinalfit
    @thefinalfit 9 місяців тому

    If you have time this weekend, can you also upload stack approach. thanks

  • @ujjawaltyagi8540
    @ujjawaltyagi8540 9 місяців тому

    Please make video on other mentioned approaches as well!!

  • @bhuppidhamii
    @bhuppidhamii 9 місяців тому

    i already solved it but here for intuition

  • @intromaker400
    @intromaker400 Рік тому +1

    Sir attach the java code on every video and also try to explain the code in java, it helps me a lot

  • @advitkothari7302
    @advitkothari7302 9 місяців тому

    gr8 ! job very helpful

  • @ManojKrVerma-vw4dx
    @ManojKrVerma-vw4dx 9 місяців тому

    Please make a video for this problem using the two pointers method

  • @udaytiwari2855
    @udaytiwari2855 6 місяців тому

    Thanks a lot.👍👍

  • @gauravbanerjee2898
    @gauravbanerjee2898 9 місяців тому

    Thanks a lot bhaiya ❤️

  • @manishv3992
    @manishv3992 9 місяців тому +2

    With stack bhaiya plz ❤

  • @purushottamkumar3140
    @purushottamkumar3140 2 роки тому +4

    int trap(vector& height) {
    int n = height.size();
    int left_max[n], right_max[n];

    int leftMax = height[0], rightMax = height[n-1];
    for(int i=0; ileftMax) leftMax = height[i];
    if(height[n-i-1]>rightMax) rightMax = height[n-i-1];
    }

    int sum = 0;

    for(int i=0; i

  • @ajinkyakhete1151
    @ajinkyakhete1151 9 місяців тому +1

    please upload monotonic stack

  • @lahirishreemanto19
    @lahirishreemanto19 3 місяці тому

    Good video, but I was expecting O(1) solution please!!

  • @factacewar
    @factacewar 6 місяців тому

    Day 2 done ✅

  • @bhaveshjhawar9532
    @bhaveshjhawar9532 11 місяців тому

    Sir please Tapping Rain Water 2 bhi solve krdijiyeeee PLEASEEEEEEEE

  • @AkOp-bf9vm
    @AkOp-bf9vm 3 місяці тому

    1.can be done with stack also?? how??
    2. i think we can do it with O(N) space only for this approach and also it can be done in O(1) space.

  • @abhishekprasad5527
    @abhishekprasad5527 9 місяців тому

    bhaiya you should consider making a-z dsa course on yt, pls bhaiya

  • @dhruvp1777
    @dhruvp1777 9 місяців тому

    youre a god

  • @youknowsuraj69.
    @youknowsuraj69. 12 днів тому +1

    Hello Mik ,
    You done a silly mistake while writing a previous element ,
    in last element of previous element its should be prev[i] = max(arr[i],prev[i-1]) = 5.
    so the previous array look like this ;-
    {4,4,4,4,4,5}

  • @harshtiwari416
    @harshtiwari416 9 місяців тому

    Bhai iski stack or dp approach bhi bana do

  • @harchitgulati3065
    @harchitgulati3065 Рік тому

    bhaiya ye stack se ho sakta hei kya using just greater element approach

  • @AnkitJain-w3l
    @AnkitJain-w3l 10 місяців тому

    Day -2

  • @sarathkumardunga5240
    @sarathkumardunga5240 2 роки тому

    Hi bhaiya! I have tried for the approach using just variables instead of arrays but i couldnt figure out.. could u help me with the approach using just the variables

    • @codestorywithMIK
      @codestorywithMIK  2 роки тому

      Can you share your code ?

    • @sarathkumardunga5240
      @sarathkumardunga5240 2 роки тому

      @@codestorywithMIK i can maintain the leftMax variable and as i go from (0 to n-1) and can update the leftMax variable if the current height of the building is > present leftMax variable. But for rightMax variable each time for the current height of the building i have to traverse all the buildings to right from the current building to figure the max height to right. Is there any way that i can figure out both leftMax height and rightMaxheight at one go.. OR do i need to change my approach??

    • @sarathkumardunga5240
      @sarathkumardunga5240 Рік тому

      @@codestorywithMIK
      int trap(vector& height) {
      //APPROACH 1: (USING 2 POINTERS)
      //TC: O(N) SC: O(1)
      int n = height.size();

      int left = 0;
      int right = n-1;
      int leftbar = height[0];
      int rightbar = height[n-1];
      int waterStored = 0;
      while(left = limmiting bar)
      // || if(currworking bar < limiting bar)
      if(height[left] >= leftbar){
      waterStored+= 0;
      leftbar = height[left];
      }
      else{
      waterStored += (leftbar - height[left]);
      }
      left++;
      }
      else{
      //same as above
      if(height[right] >= rightbar){
      waterStored+= 0;
      rightbar = height[right];
      }
      else{
      waterStored += (rightbar - height[right]);
      }
      right--;
      }
      }

      return waterStored;
      }
      --------------------------------------------------------------------------------------------------------
      /* //APPROACH 2
      // TC: O(N) SC: O(N)
      int n = height.size();

      vector rmax(n, 0); //for an element i , rmax[i] represents the highest building to its right
      vector lmax(n, 0);
      rmax[0] = height[0];
      lmax[n-1] = height[n-1];
      for(int i = 1 ; i < n; i++){
      rmax[i] = max(rmax[i-1], height[i]);
      lmax[n-i-1] = max(lmax[n-i], height[n-i-1]);
      }
      int waterStored = 0;
      for(int i = 0 ; i < n; i++){
      int waterOnTop = min(rmax[i], lmax[i]) - height[i];
      waterStored += waterOnTop;
      }
      return waterStored;
      }
      */

    • @aws_handles
      @aws_handles 9 місяців тому

      Difficult with just variables

  • @Pranav_147
    @Pranav_147 4 місяці тому

    A SMALL MISTAKE BRO........LEFT MAX AT 5TH INDEX IS 5 NOT 4

  • @Nofaltuguy1
    @Nofaltuguy1 9 місяців тому

    hehe daily challenge guys