Trapping Rainwater Problem | Leetcode #42

  Рет қаралды 97,826

Techdose

Techdose

Күн бұрын

This video explains a very important programming interview problem which is the trapping rainwater problem.In this problem, given an array representing elevation map, we are required to find the amount of water the elevation map can trap.I have explained all the approaches for solving this problem starting from the bruteforce approach to the most optimal approach.I have shown how we can process and highly optimize the time complexity.
CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
======================================PLEASE DONATE=============================
🧡 SUPPORT OUR WORK: / techdose
💚 UPI-ID: surya.kahar@ybl
💞JOIN Membership: / @techdose4u
==============================================================================
INSTAGRAM : / surya.pratap.k
LinkedIn: / surya-pratap-kahar-47b...
WEBSITE: techdose.co.in/
TELEGRAM Channel LINK: t.me/codewithT...
TELEGRAM Group LINK: t.me/joinchat/...
=======================================================================
USEFUL LINKS:
🟠Must do TIPS to ACE Virtual Interview: • 🔴Must do Tips to ACE y...
🟢Best strategy to excel your coding interview: • 🔴Best strategy to exce...
🟡Get your dream job in 1 month: • 🔴Get your dream job in...
🔵How to crack dream job in just 2 months: • How to crack dream job...
🟣7 Days DSA plan: techdose.co.in...
RELATED LINKS:
Maximum of all subarrays of size K: • Maximum of all subarra...
Perfect Subarray: • Perfect subarray | Goo...
CODE LINK: techdose.co.in...

Пікірлер: 246
@TW-uk1xi
@TW-uk1xi 3 жыл бұрын
This is one of the best explanations I've seen so far on the internet.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@EngWorld-nr2ww
@EngWorld-nr2ww 3 жыл бұрын
Your patience while explaining is quite appreciable
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@mwshubham
@mwshubham 3 жыл бұрын
This might be the longest video on your channel. Very well covered. Thank you :)
@techdose4u
@techdose4u 3 жыл бұрын
Welcome
@abhilashpatel3036
@abhilashpatel3036 3 жыл бұрын
i did not even notice. Time flies.
@MdOwaisUmar
@MdOwaisUmar 2 жыл бұрын
@@abhilashpatel3036 Absolutely, Time flies, but leaves its shadow behind.
@rtan8780
@rtan8780 3 жыл бұрын
Dang man, you made a Leetcode Hard problem seem like an Easy. Subscribed :)
@techdose4u
@techdose4u 3 жыл бұрын
👍🏼
@muwongenicholus2444
@muwongenicholus2444 2 жыл бұрын
Hehehe, I was thinking the same thing. Some people are natural teachers.
@gsmdfaheem
@gsmdfaheem Жыл бұрын
Hands down the best explanation on youtube... Better than top creators.
@user-oy4kf5wr8l
@user-oy4kf5wr8l 3 жыл бұрын
After finding ur videos, i never watch any other channel.... i super like how u explain stuff, and different improved ways to solve it. thank you man!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@stephc4925
@stephc4925 2 жыл бұрын
One of the best explanations! Thanks a lot!
@techdose4u
@techdose4u 2 жыл бұрын
Welcome :)
@codingessential91
@codingessential91 3 жыл бұрын
great video sir, i had come to understand the O(1) space solution, and your explanation is shorter and much much crisper than anyone else's. keep up the great work.
@suryajena1575
@suryajena1575 3 жыл бұрын
Happy Teacher's day. Really appreciate you as a teacher.
@paramitagorai9087
@paramitagorai9087 2 жыл бұрын
Generally dont prefer commenting unless really impressed. This was a great solution and I could code very easily myself. thanks for all the effort spent.
@techdose4u
@techdose4u 2 жыл бұрын
Welcome :)
@gautam4696
@gautam4696 3 жыл бұрын
The solution of this problem is very simple but the way sir tells how to approach a problem is amazing .
@techdose4u
@techdose4u 3 жыл бұрын
:)
@amitavamozumder73
@amitavamozumder73 3 жыл бұрын
It's rare to have a video with zero downvotes! great explanation.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@shantanusharma184
@shantanusharma184 2 жыл бұрын
Your explanation resolved all my doubts and i was able to write code by myself after watching your video for 10 minutes. Thank you
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@mridulsemwal1396
@mridulsemwal1396 2 жыл бұрын
No one explains like this. Loved your videos
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@DK-ox7ze
@DK-ox7ze 2 жыл бұрын
Awesome explanation, covering all cases with detail and clarity!
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@sugandhaduhan8707
@sugandhaduhan8707 Жыл бұрын
Best video on internet for Trapping Rain water.. I wouldn't have understood this problem if I hadn't found this video... Kudos for the great explanation....
@YashHalgaonkar
@YashHalgaonkar 3 жыл бұрын
Your channel is really great! You should definitely have more subscriber than most of other creators who create useless roadmaps.
@biswajitsingh8790
@biswajitsingh8790 2 жыл бұрын
Hands down the best explanation of this problem on the internet. 🙏🙏
@PRUTHVIRAJRGEEB
@PRUTHVIRAJRGEEB 3 жыл бұрын
This is hands down the best explanation I have seen for this question. I am surprised it doesn't have many views!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@MohitKumar-rq8hv
@MohitKumar-rq8hv 2 жыл бұрын
TC =O(n) SC =O(1) => 24:25 superb explaination
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@01kumarr
@01kumarr Жыл бұрын
giving all three possible solutions u make life easy. Thanks a lot
@ajaygonepuri2285
@ajaygonepuri2285 Жыл бұрын
You Deserve more than a million subscribers for such a great content!
@techdose4u
@techdose4u Жыл бұрын
Thanks :)
@ayushsrivastava830
@ayushsrivastava830 2 жыл бұрын
Awesome Explanation, better from other KZbinrs
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@muwongenicholus2444
@muwongenicholus2444 2 жыл бұрын
You sir, did an awesome job breaking this down and making it simpler to understand. Thank you for your efforts. Appreciate it
@flyingcanopy5611
@flyingcanopy5611 3 жыл бұрын
I watched many videos to understand the concept of two pointer approach.. But after watching this video, It became so clear to me.... Next time if I am unable to solve any question I will come to this channel first... This is a very underrated channel..
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@sukeshreddy2286
@sukeshreddy2286 2 жыл бұрын
You are the best. I am now sharing with my friends!!
@pkboolean
@pkboolean 3 жыл бұрын
thank you for this, this is extremely well explained
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@kambalavijay6800
@kambalavijay6800 2 жыл бұрын
Techdose to me is a game changer
@ravikumar-kh9gi
@ravikumar-kh9gi 2 жыл бұрын
Awesome explanation . Even kids can understand after watching this video. Thank you very much
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😁
@venup2813
@venup2813 2 жыл бұрын
Most underrated channel
@chhavimishra3469
@chhavimishra3469 2 жыл бұрын
When the content is so good, subscribing and liking are on autopilot.
@jiosim1377
@jiosim1377 3 жыл бұрын
Thanks alot! I was struggling to understand the logiv but now its clear
@techdose4u
@techdose4u 3 жыл бұрын
Great
@huansir1922
@huansir1922 2 жыл бұрын
thank you for your explain , from simple solution to better solution !
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😊
@PRASHANTKUMAR-xs9pk
@PRASHANTKUMAR-xs9pk 3 жыл бұрын
In every Questions , too much concept as well as hidden cases . When i want to try same questions after 4 days or a week i got stuck but your explanation make question easier for me. ::))
@techdose4u
@techdose4u 3 жыл бұрын
Great :)
@kushagrashekhawat8227
@kushagrashekhawat8227 2 ай бұрын
I've watched many of your videos. Your explanations are always very easy to understand. Thank you for creating these videos; you are doing so much good.
@techdose4u
@techdose4u 2 ай бұрын
thanks :)
@sanketgupta9831
@sanketgupta9831 2 жыл бұрын
Best explanation ever with best level of calmness and patience 😊😊
@neerajpandey7273
@neerajpandey7273 3 жыл бұрын
I had seen your video of solving the area of histogram ..so first thing came in my mind to take 2 stacks to get left and right max ...while writing the code I realized that I can solve this without stack .... after that I saw your complete video and got o(1) space method ... this is crazy
@techdose4u
@techdose4u 3 жыл бұрын
😂 hahaha. Very nice to see you apply the concepts of my previous video :) But there is always someone better than you 😉
@neerajpandey7273
@neerajpandey7273 3 жыл бұрын
@@techdose4u =D =D
@calisthenics-
@calisthenics- 2 жыл бұрын
Champ tech dose🙏 👏 Well done
@Harsh-og5xr
@Harsh-og5xr Жыл бұрын
loved that o(1) space method
@varshaprajapati6566
@varshaprajapati6566 2 жыл бұрын
thankyou so much for this video! you just made this hard task quite easy.
@chandrachurmukherjeejucse5816
@chandrachurmukherjeejucse5816 Жыл бұрын
So far the best explaination. Thank you so much sir.
@nishantpratyush4191
@nishantpratyush4191 2 жыл бұрын
I bet this vdo has got the best explanation for the two pointer approach...thanks a ton TechDose😊
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😄
@santhoshmedide5279
@santhoshmedide5279 3 жыл бұрын
The last solution where time-O(N) and space-O(1) method is amazing. Came here after many leetcode solutions!
@nikitakushwaha9572
@nikitakushwaha9572 2 жыл бұрын
You are very easy and nice to understand.
@techdose4u
@techdose4u 2 жыл бұрын
Thanks ☺️
@beginnerprogrammingtutoria5053
@beginnerprogrammingtutoria5053 3 жыл бұрын
An incredibly detailed and amazing presentation. Thank you!
@coderart__2802
@coderart__2802 3 жыл бұрын
Thanks for this beautiful video, your explanation made me code myself... At the end of 16 min of the video, I understood and coded in python.
@manojbhatt8424
@manojbhatt8424 Жыл бұрын
brooooooooooooooooo best explaination ever
@techdose4u
@techdose4u Жыл бұрын
Thanks :)
@PujaKumari-rp5sg
@PujaKumari-rp5sg Жыл бұрын
sir you explained very nicely step by step 👌👌👌
@aniketroy03
@aniketroy03 3 жыл бұрын
Great video sir!! What an explanation! Keep uploading such videos 🙏🙏
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@sumit180288
@sumit180288 2 жыл бұрын
Very good explanation
@ravisankarmaruramesh8112
@ravisankarmaruramesh8112 3 жыл бұрын
Index starts from 1 to arr.len-1 Totalwater+=Math.min(leftmax of current index element, rightmax of current index element)-current index element
@techdose4u
@techdose4u 3 жыл бұрын
Nice 1 liner :)
@rajivsarkar277
@rajivsarkar277 3 жыл бұрын
Ur patience is appreciable
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@NaveenRawat51
@NaveenRawat51 3 жыл бұрын
awesome explanation, the way you explained corner cases are great. keep it up
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@rachanasingh7047
@rachanasingh7047 3 жыл бұрын
Best solution explaination to this problem. 🙌
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@akashjain4281
@akashjain4281 3 жыл бұрын
The best explanation for the problems, Ty sir for ur patience and amazing explanations
@bloody9162
@bloody9162 2 жыл бұрын
It's sad KZbin has hidden dislikes on a video, stops good videos like this from showing up first. Thanks. 38k views and 1.2k likes? c'mon guys hit the like button.
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@gamingKlips99
@gamingKlips99 3 жыл бұрын
what a coincidence that we both were working on the same problem.
@techdose4u
@techdose4u 3 жыл бұрын
:O
@harshavarthinivr9688
@harshavarthinivr9688 2 жыл бұрын
Very nice explanation 👌thank youu
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😀
@krishnananddubey2870
@krishnananddubey2870 3 жыл бұрын
Just explained it calmly loved that.🤗
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@sumeetchawla3545
@sumeetchawla3545 2 жыл бұрын
Thanks a ton for explaining solution in detail. It's really a tough job. Keep it up!!!
@spaceship-rl5fp
@spaceship-rl5fp 5 ай бұрын
Excellent Explanation
@khushbukareliya8999
@khushbukareliya8999 3 жыл бұрын
Best Explanation.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@basiljacob3894
@basiljacob3894 3 жыл бұрын
Very well explained sir , your explanation for this question is crystal clear. I really liked this problem it was very intuitive
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@sujitha2339
@sujitha2339 2 жыл бұрын
Clear explanation!! Thanks bro
@harikakiran18
@harikakiran18 3 жыл бұрын
Nicely explained step by step, appreciated it, understood the approach in one go...you deserve more subs & views...hope you will reach there ..:)
@techdose4u
@techdose4u 3 жыл бұрын
Thanks ❤️
@harishkandikatla9791
@harishkandikatla9791 3 жыл бұрын
Excellent explanation! Your channel will definitely grow a lot
@techdose4u
@techdose4u 3 жыл бұрын
Thanks 😊
@sandeepkharola6463
@sandeepkharola6463 2 жыл бұрын
Great work Keep going 👍
@simrankak7045
@simrankak7045 3 жыл бұрын
amazing crystal clear explaination
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@CSe_IT_Guy
@CSe_IT_Guy 2 жыл бұрын
Best explanation 👏
@techdose4u
@techdose4u 2 жыл бұрын
Thanks ☺️
@monikavaid5083
@monikavaid5083 2 жыл бұрын
Very good solution!,
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@prakharagarwal6237
@prakharagarwal6237 3 жыл бұрын
Nice Explanation! Thanks!
@hnsc1
@hnsc1 3 жыл бұрын
Thank you for this video! I appreciate you drawing out the base cases and explaining everything in detail. This is definitely the most helpful video for this problem :)
@gurubalaji5611
@gurubalaji5611 3 жыл бұрын
Great explanation sir..hope expecting more videos from tech dose..
@techdose4u
@techdose4u 3 жыл бұрын
Sure. I will keep uploading :)
@athisii_ekhe6167
@athisii_ekhe6167 Жыл бұрын
you made it easy. Thank you.
@yashkhandelwal6588
@yashkhandelwal6588 3 жыл бұрын
Thank you so much you explained these questions by previously known methods because others are making it very complicated for reducing code size()
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@egor.okhterov
@egor.okhterov 2 жыл бұрын
As we go from left to right `max_left` could only increase (or stay the same). As we go from right to left `max_right` could only increase (or stay the same). That is why when we move pointers L and R, `max_left` and `max_right` compete with each other. First one gets larger, then the other gets larger, then the other gets larger. And we swing from one side to the other side moving pointer L and R closer to each other.
@arjunadityarastogi2118
@arjunadityarastogi2118 3 жыл бұрын
Thank you , Just THANK YOU
@huseyinbarin1653
@huseyinbarin1653 2 жыл бұрын
very clear explanation!
@basictechs6634
@basictechs6634 2 жыл бұрын
Great explanation, thank you.
@playing_rhythms2660
@playing_rhythms2660 3 жыл бұрын
I think in the last condition it will be (l
@ethanzhao5729
@ethanzhao5729 3 жыл бұрын
Your explanation fits the process of how to solve a problem -- from observation of cases to generalization to optimization to final code. Pure memorization of the solution without following this process is not helpful to interviews
@viveknandan4950
@viveknandan4950 3 ай бұрын
Nice explanation.
@cs-ope
@cs-ope Жыл бұрын
Great explanation!
@paragroy5359
@paragroy5359 3 жыл бұрын
Nice explanation sir......you are doing a great job
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@mpavankumar6695
@mpavankumar6695 2 жыл бұрын
Great explanation
@elitesharma817
@elitesharma817 3 жыл бұрын
Right at 21:35 I stopped and boom my code got accepted, thanks a lot bhai, I was trying to solve with 2 pointer approach as well but couldn't deal with the water-level stuff, which you made so easy to understand and grasp, and not just that also for improvising code in such an awesome way with 2N Auxiliary space. Again thanks a lot bhai
@depression_plusplus6120
@depression_plusplus6120 3 жыл бұрын
Nobody cares thou...keep coding
@akshitjain2906
@akshitjain2906 Жыл бұрын
amazing explanation bro!
@GauravKumar-ue7nz
@GauravKumar-ue7nz 2 жыл бұрын
Best explanation
@CodeSuccessChronicle
@CodeSuccessChronicle 3 жыл бұрын
Thank you so much for doing this on my request.... best bro...
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@vaishaligoyal7478
@vaishaligoyal7478 3 жыл бұрын
Simply Amazing!!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks ☺️
@elenamikhaylova4287
@elenamikhaylova4287 11 ай бұрын
nicely covered thank you
@krupaharan9406
@krupaharan9406 3 жыл бұрын
This saved my day :-) Thank you very much
@techdose4u
@techdose4u 3 жыл бұрын
:)
@abhinavmudgal7355
@abhinavmudgal7355 2 жыл бұрын
Best solution
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😃
@milenitrivedi7561
@milenitrivedi7561 2 жыл бұрын
great explanation !!
@sanjeevacham2400
@sanjeevacham2400 2 жыл бұрын
Excellent
@techdose4u
@techdose4u 2 жыл бұрын
Thanks
@nareshh74
@nareshh74 Жыл бұрын
Thanks for the video. Can u logically explain how u chose 2 pointers approach?
@TEJASSADADE
@TEJASSADADE Жыл бұрын
you r best
@techdose4u
@techdose4u Жыл бұрын
Thanks :)
@venup2813
@venup2813 2 жыл бұрын
You are legend 🔥🔥🔥
@RayTayek
@RayTayek 5 ай бұрын
very nice. thank you
@wjrasmussen666
@wjrasmussen666 Жыл бұрын
This problem is kind of cool.
Sliding Window Maximum | Leetcode #239
25:38
Techdose
Рет қаралды 53 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 204 М.
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 35 МЛН
Trapping Rain Water - Leetcode 42 - 2 Pointers (Python)
9:51
Remove K digits | Build lowest number | Leetcode #402
15:30
Techdose
Рет қаралды 88 М.
L8. Trapping Rainwater | 2 Approaches | Stack and Queue Playlist
28:58
Trapping Rain Water - Google Interview Question - Leetcode 42
23:21
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 492 М.
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4,1 МЛН
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 35 МЛН