Trapping Rain Water || Best optimization || O(N) Time O(1) space || Intuition with Code and Example

  Рет қаралды 17,365

Code with Alisha

Code with Alisha

2 жыл бұрын

Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the rainy season.
Input:
N = 6
arr[] = {3,0,0,2,0,4}
Output:
10
Explanation:

Пікірлер: 78
@jatinbhatoya8420
@jatinbhatoya8420 2 жыл бұрын
oh god, you explained better than striver. hats off. Once you said the word limiting, i understood the whole algo and coded it myself.
@piyushsingh9320
@piyushsingh9320 2 жыл бұрын
true,better then big youtube channels
@yeswanthh5068
@yeswanthh5068 Жыл бұрын
Yaa🔥🔥
@anandyadav_
@anandyadav_ Жыл бұрын
true!! limiting word helped : )
@lostcyrus8578
@lostcyrus8578 Жыл бұрын
i also came after watching striver..you explained better
@radhikagokani3660
@radhikagokani3660 Жыл бұрын
Exactly !! Was working on the problem for hours ! LIMITING was the word that made everything clear !!
@RassieVanderDussen-mc8um
@RassieVanderDussen-mc8um Жыл бұрын
It never happened that I came to understand the solution from your video and not understand it. Your intution and approach are so easy to understand. Thanks and please continue this great work.
@hema4266
@hema4266 7 ай бұрын
You used the right words to build intuition and everything seemed so simple!!!! Thanks a lot
@SirAkPandey
@SirAkPandey Жыл бұрын
Hats off to your efforts.. You're the most underrated educator on this platform 🙏🙏
@krishnasahay9694
@krishnasahay9694 Жыл бұрын
Finally got an approach with constant space. Best explanation!!
@aishwaryakulkarni9452
@aishwaryakulkarni9452 11 ай бұрын
This was the best explanation so far, concepts are clear! Thanks a bunch🥺 Your channel is so underrated :(
@b2aquantschool798
@b2aquantschool798 4 ай бұрын
Even this video is two year old and I am watching it right now, after watching multiple other video solutions ,I can confidently say that your explanation is the best out of all I have watched till now. This video is ever green. Thanks for your effort. Please Don't quit from making this type of video, keep it up at least for your viewers. The only word I can say about this video is "Excellent".
@raufurkhan9191
@raufurkhan9191 Жыл бұрын
Such an easy and lucid explanation. One of best explanation..Kudos..🙂
@anonXoXoXo
@anonXoXoXo 5 ай бұрын
oh my god,such a nice explanation . its not just this question ,when no one is able to make me understand the solution ,its always your solution which help me understand .
@rudra-18
@rudra-18 Жыл бұрын
Nice explanation with such a clean code!
@bhargavinaik8145
@bhargavinaik8145 4 ай бұрын
Thank you so much for this explanation, I had solved it with 2 arrays, was struggling alot to understand the O(1) space logic. The words you used really helped to unlock that link.
@naredlaaalana9371
@naredlaaalana9371 4 ай бұрын
Thanks for the detail explanation. Now I got to understand the intuition behind using the two pointer approach to this problem
@ashishtiwari6000
@ashishtiwari6000 2 жыл бұрын
Must say you are simply awesome !!!!!!
@rabindrapatra7151
@rabindrapatra7151 Ай бұрын
Beautiful
@bharathkumar5870
@bharathkumar5870 2 жыл бұрын
thanks again,learning important problems from ur channel
@harish5466
@harish5466 Жыл бұрын
Best and easy explanation have ever seen. Thank you
@ashutoshlawaniya9833
@ashutoshlawaniya9833 2 жыл бұрын
Really, it is awesome 🔥 Keep it up .
@yeswanthh5068
@yeswanthh5068 Жыл бұрын
Wonderfull explanation,thank u very much 🙂🙂
@Yash-fh7gm
@Yash-fh7gm Жыл бұрын
thanks for this great video and amazing explanation
@addankihasith4672
@addankihasith4672 7 ай бұрын
Thanks for the explanation and the efforts you put in making things simpler in this video
@KunalSharma-cj5hc
@KunalSharma-cj5hc 2 жыл бұрын
Very nice explanation literally. You just gained one subscriber.
@brijrajsinhgohil6576
@brijrajsinhgohil6576 Жыл бұрын
your intuition is the best!
@avijitmaity7436
@avijitmaity7436 2 жыл бұрын
the explanation is to clean to understand the problem and also simple. thanks
@rohithjakkani8343
@rohithjakkani8343 Жыл бұрын
Very nice and fast Explaination.Good Concentration till last minute.
@jagan2350
@jagan2350 Жыл бұрын
your explanation for the problem are greater ,thank you for the video, it was very useful to me
@rinkygarg7350
@rinkygarg7350 5 ай бұрын
though I saw this approach many times but couldn't understand before so keep looking for more. Only, in this video, I could actually feel that I understood the concept. Thanks and keep it up. 👌👌👏👏
@sudeepgupta57
@sudeepgupta57 Ай бұрын
Thanks for the great explanation
@bishaladhikari9499
@bishaladhikari9499 Жыл бұрын
Brilliant!
@gauravverma2901
@gauravverma2901 Жыл бұрын
Thank you so much ma'am for such a great Explanation😍
@lakshyakumawat9710
@lakshyakumawat9710 Жыл бұрын
Great explanation 🔥
@bikramshahi8512
@bikramshahi8512 2 жыл бұрын
great explanation , you deserve more likes and suscribers....
@danussh
@danussh 2 жыл бұрын
Perfect😍
@techiestart3233
@techiestart3233 2 жыл бұрын
U are doing great job 🤩thankyou so much for sharing your knowledge.please also make a video on your interview questions
@arshdeep011
@arshdeep011 Жыл бұрын
Best video for this problem!
@adityaband6919
@adityaband6919 Жыл бұрын
amazing explanation
@kumaravinashsinghabnish4021
@kumaravinashsinghabnish4021 10 ай бұрын
Really underestimated teacher you are 🎉😮 Awesome 💯 I had watched almost 7 videos of you since morning 🌅 Exclaimed Explained
@gitanjalikumari9262
@gitanjalikumari9262 22 күн бұрын
Thankyou.. great explanation really😊
@sheraurshayri2033
@sheraurshayri2033 7 ай бұрын
nice explanation than striver greatttttt
@Mahmmadhusen072
@Mahmmadhusen072 2 жыл бұрын
best video thanks. i understood
@ManishKumar-jz2jr
@ManishKumar-jz2jr Жыл бұрын
Great explanation. Subscribed
@abhishekkarn8918
@abhishekkarn8918 2 ай бұрын
Uncle is extremely cute btw :). Great video though Alisha :)
@charand9597
@charand9597 Жыл бұрын
very intutive explanation brilliant👑👑👑👑👑👑
@priyankpatel1580
@priyankpatel1580 Жыл бұрын
Greatest explanation ❤🎉 tnx
@drizzle01
@drizzle01 11 ай бұрын
20:04 Uncle ji parnam XD, great explanation btw!
@ankit80354
@ankit80354 Жыл бұрын
thankuu so much dear🥰.
@rakshitbro7601
@rakshitbro7601 Ай бұрын
you strudied from striver and explained bettter than him very well alisha
@narendra7556
@narendra7556 2 жыл бұрын
great Alisha thank you
@kushalshukla444
@kushalshukla444 Жыл бұрын
nice explanation
@Alan-bu2hi
@Alan-bu2hi 19 күн бұрын
Thank you!!!!!
@ProgBoost
@ProgBoost Жыл бұрын
Thank a lot ☺
@nagendrapp2213
@nagendrapp2213 2 жыл бұрын
nice explanation and if you don't mind could you please reduce the screen size (zoom out ) for all your videos so I can able to see whole code (screen) and also please make a video on how to maintain the consistency (problem solving ) 😊
@ayushsinghrathore360
@ayushsinghrathore360 Жыл бұрын
Thanks 👍🙏
@maddycoder1294
@maddycoder1294 2 жыл бұрын
its very helpful thanku
@SleepeJobs
@SleepeJobs 2 жыл бұрын
Thank you ma'am.
@raedhasan2240
@raedhasan2240 11 ай бұрын
thank you
@shivanshgupta1509
@shivanshgupta1509 2 жыл бұрын
ThankYou mam!!!
@venkataramanan6354
@venkataramanan6354 Жыл бұрын
Nice explaination, Can you please create a video for time management, like the sleep crisis during preparation, It feels like a sleep deprivation is on the way, please help tackling.🙂
@shubhamsukum
@shubhamsukum Жыл бұрын
Thanks!!
@sharadkumar6658
@sharadkumar6658 Жыл бұрын
Nice mam. It was quite good solution.😇😇
@sharadkumar6658
@sharadkumar6658 Жыл бұрын
Mam plz upload leetcode daily solution too.🙏🙏 It really help a lot..
@nasirkhansirajbhai8016
@nasirkhansirajbhai8016 Жыл бұрын
amazing skills.. thank you, could you please post some content on linkedin as well?
@expert_solver
@expert_solver Жыл бұрын
when you said limiting bar decide ans that point, game is over👍
@user-sm7zo5zd9t
@user-sm7zo5zd9t 2 ай бұрын
Thanks mam
@satyajeetkumarjha1482
@satyajeetkumarjha1482 2 жыл бұрын
Actually, ur code could have been more intuitive if u calculated left max and right max and then did leftmax
@AnoopSingh-hx4wm
@AnoopSingh-hx4wm Жыл бұрын
tq mam 🤗
@saveethanotessharingsharee1155
@saveethanotessharingsharee1155 Жыл бұрын
Can u explain on placement problems of java
@devadityasati7757
@devadityasati7757 Жыл бұрын
i love your way n u
@SelfImprovementtip
@SelfImprovementtip 2 ай бұрын
class Solution { public int trap(int[] height) { if (height == null || height.length == 0) { return 0; } int left = 0; // Initialize left pointer int right = height.length - 1; // Initialize right pointer int leftMax = height[left]; // Maximum height to the left int rightMax = height[right]; // Maximum height to the right int ans = 0; // Variable to store the total water trapped while (left < right) { if (leftMax < rightMax) { // If leftMax is less than rightMax, process the left side left++; leftMax = Math.max(leftMax, height[left]); ans += Math.max(0, leftMax - height[left]); } else { // If rightMax is less than or equal to leftMax, process the right side right--; rightMax = Math.max(rightMax, height[right]); ans += Math.max(0, rightMax - height[right]); } } return ans; } }
@youtubechannel-ub1xr
@youtubechannel-ub1xr 3 ай бұрын
491 likes are too less for your explnation!
@prajjwaldubey5787
@prajjwaldubey5787 8 ай бұрын
the space complexity is O(n) not O(1) as you mentioned it in thumbnail please change it
@studywithsmartwork9953
@studywithsmartwork9953 Ай бұрын
we are not using any array or stack so how the sc is o(n)
@vinamrasangal8436
@vinamrasangal8436 Жыл бұрын
alisha ,u r a gud girl
Trapping Rain Water - Google Interview Question - Leetcode 42
23:21
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 7 МЛН
Oh, wait, actually the best Wordle opener is not “crane”…
10:53
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 808 М.
Trapping Rainwater Problem | Leetcode #42
34:12
Techdose
Рет қаралды 96 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 289 М.
Trapping Rainwater | Brute | Better | Optimal | with INTUITION
23:23
take U forward
Рет қаралды 266 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 860 М.
Leetcode Decode Ways || Intuition + Code + Explanation
31:49
Code with Alisha
Рет қаралды 15 М.
Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
20:09
take U forward
Рет қаралды 365 М.