Trapping Rain Water - Leetcode 42 - 2 Pointers (Python)

  Рет қаралды 12,883

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 34
@GregHogg
@GregHogg 5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@hlubradio2318
@hlubradio2318 7 ай бұрын
Hey Greg FYI the more I have been watching your videos for a few weeks now and I can say you're a genuis.
@GregHogg
@GregHogg 6 ай бұрын
Lololol thank you!!
@electric336
@electric336 Ай бұрын
This was a great explanation. I did not even think about treating each index as an individual column of water. I was traversing the array to look for valleys, which made the code much more complicated.
@hlubradio2318
@hlubradio2318 7 ай бұрын
Actually Greg is beyond all of my college professors.
@GregHogg
@GregHogg 6 ай бұрын
Awe haha
@saaddude1
@saaddude1 6 ай бұрын
Thanks for explaining this problem in such an easy way!
@GregHogg
@GregHogg 6 ай бұрын
Glad to hear it 😊
@CharlesMurphy1000
@CharlesMurphy1000 2 ай бұрын
Thanks for the great explanation. Although this is not a two pointer solution, your explanation helped me understand the intuition behind how a two pointer solution works; the one that dynamically keeps track of the left and right max value. Your videos are great, keep them coming!
@christianjt7018
@christianjt7018 5 ай бұрын
Great explanation, you made this hard problem really easy to understand
@GregHogg
@GregHogg 4 ай бұрын
Oh I'm really happy to hear that
@dejaphoenix
@dejaphoenix 4 ай бұрын
These videos that end with "there's a more efficient method but it's pretty complicated" I would love to see a separate video anyway to describe it. Heck, a whole playlist of "the harder way" videos. Or at least a Wikipedia link in the description describing the harder, more efficient algorithm.
@GregHogg
@GregHogg 4 ай бұрын
Sorry about that!!
@shivamguys
@shivamguys 3 ай бұрын
Love the way you explain
@jassemtoumi2876
@jassemtoumi2876 6 ай бұрын
Great Explanation !! keep it up
@khadijaashraf
@khadijaashraf 2 ай бұрын
awesome visualization! would love to see the O(1) space solution too.
@NSSanya
@NSSanya 2 ай бұрын
very nice explanation! cheers
@tanmaysharma3908
@tanmaysharma3908 2 ай бұрын
heyy man! great work, i love you!!!
@venkatamallapu
@venkatamallapu 4 ай бұрын
if you were not going to show 2 pointers then why did you have it in the title.
@dharun1510
@dharun1510 8 ай бұрын
Thank man, it is really helpful keep up the Good work. ☺
@X3Maverick
@X3Maverick 5 ай бұрын
Seems like you should take "2 Pointers" out of the video title.
@GregHogg
@GregHogg 5 ай бұрын
Nah, that's the name of the algorithm
@X3Maverick
@X3Maverick 5 ай бұрын
​@@GregHogg No, this is a 1 pointer solution. The solution you allude to at the end of the video is a 2 pointer solution.
@MrEmbrance
@MrEmbrance 19 күн бұрын
this is not 2 pointers approach - this is DP
@kasmdeliac3264
@kasmdeliac3264 24 күн бұрын
why is the title 2 pointer if its not the solution of it?
@ravi19900
@ravi19900 3 күн бұрын
Test case failed height = [0,1,0,2,1,0,1,3,2,1,2,1] Output - 11 Expected = 6 class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int """ l_wall = r_wall= 0 n = len(height) max_left = [0] * n max_right = [0] * n for i in range(n): j = -i-1 max_left[i] = l_wall max_right[i] = r_wall l_wall = max(l_wall, height[i]) r_wall = max(r_wall, height[j]) summ = 0 for i in range(n): pot = min(max_left[i] , max_right[i]) summ += max(0, pot - height[i]) return summ
@malakggh
@malakggh 2 ай бұрын
Thank you for saying it's stupidity hard 😂😂
@nandepucharitha9049
@nandepucharitha9049 8 ай бұрын
thanks man
@GregHogg
@GregHogg 8 ай бұрын
My pleasure, thank you so much for your support!
@anandreddy1976
@anandreddy1976 3 ай бұрын
class Solution: def trap(self, height: List[int]) -> int: n = len(height) max_L = float('-inf') max_R = float('-inf') L = 0 R = n - 1 count = 0 if n == 0 or n == 1: return 0 while L
@rahulan9303
@rahulan9303 4 ай бұрын
This is not an optimal solution, and you are misguiding
@AdityaRaj-lj5wf
@AdityaRaj-lj5wf 4 ай бұрын
this was not two pointers technically
@MrEmbrance
@MrEmbrance 19 күн бұрын
it's good solution, but it's not "2 pointers", it's DP
@GeraudKAMENI
@GeraudKAMENI Ай бұрын
This is not the best solution, and it's not a two-pointer approach either!!
4Sum - Leetcode 18 - Two Pointers (Python)
4:05
Greg Hogg
Рет қаралды 3,5 М.
Trapping Rain Water - Google Interview Question - Leetcode 42
23:21
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Coin Change - Leetcode 322 - Dynamic Programming (Python)
15:27
Pacific Atlantic Water Flow - Leetcode 417 - Graphs (Python)
17:10
Prefix Sum in 4 minutes | LeetCode Pattern
4:13
AlgoMasterIO
Рет қаралды 9 М.
TRAPPING RAIN WATER | LEETCODE 42 | PYTHON SOLUTION
21:04
Cracking FAANG
Рет қаралды 2,4 М.
Daily Temperatures - Leetcode 739 - Stacks (Python)
12:35
Greg Hogg
Рет қаралды 8 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 1 МЛН
Recursive Backtracking - DSA Course in Python Lecture 14
12:58