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
@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)
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 ❤️❤️
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}
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 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??
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
Thank you so much Abhay 😇❤️🙏
Currently at 4:26 , Stopped the video, tried it by myself and boom done! Thank you so much Mik!
I completed your arrays playlist 2 days ago binge watched all of them. today solved this on my own. thanks a lot
which is his arrays playlist? I only found this one? Can you show me the playlist you're talking about?
Thanks
This channel is a blessing. What a fine explanation.
bro, you just killed it
Aapka explanation boht hi easy & top quality hota h hmesa. Thank you very much bhai. Happy Eid🎉
Congratulations in advance for 41K. your channel will blast and will reach soon to 1M
the legend is here
I was Expecting O(1) space By seeing the thumbnail !!
mind blowing. i now comment on every video of yours because you are too good man
OMG, ITS SOMTING HERD FOR ME, BUT FINALLY DONE 💜💜
what a fabulous explanation..
Thank you 🙏😇
Good approach brother thank you
I was able to code on my own (: Great explanation
Sir what an amazing and simple explaination!
Thanks a lot!
just earned a sub bro, keep up the good work
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.
@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)
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 ❤️❤️
Now I feel, this problem should be marked as easy on leetcode 😊.
If you have time this weekend, can you also upload stack approach. thanks
Please make video on other mentioned approaches as well!!
i already solved it but here for intuition
Sir attach the java code on every video and also try to explain the code in java, it helps me a lot
Yes yes.
Now all videos have JAVA code also ❤️🙏
gr8 ! job very helpful
Please make a video for this problem using the two pointers method
Thanks a lot.👍👍
Thanks a lot bhaiya ❤️
With stack bhaiya plz ❤
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
please upload monotonic stack
Good video, but I was expecting O(1) solution please!!
Day 2 done ✅
Sir please Tapping Rain Water 2 bhi solve krdijiyeeee PLEASEEEEEEEE
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.
bhaiya you should consider making a-z dsa course on yt, pls bhaiya
youre a god
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}
Bhai iski stack or dp approach bhi bana do
bhaiya ye stack se ho sakta hei kya using just greater element approach
Day -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
Can you share your code ?
@@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??
@@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;
}
*/
Difficult with just variables
A SMALL MISTAKE BRO........LEFT MAX AT 5TH INDEX IS 5 NOT 4
hehe daily challenge guys