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

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 30

  • @GregHogg
    @GregHogg  4 місяці тому +1

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @hlubradio2318
    @hlubradio2318 6 місяців тому +10

    Actually Greg is beyond all of my college professors.

  • @hlubradio2318
    @hlubradio2318 6 місяців тому +10

    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 місяців тому +1

      Lololol thank you!!

  • @electric336
    @electric336 25 днів тому

    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.

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

    Thanks for explaining this problem in such an easy way!

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

      Glad to hear it 😊

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

    Great explanation, you made this hard problem really easy to understand

    • @GregHogg
      @GregHogg  4 місяці тому +1

      Oh I'm really happy to hear that

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

    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  3 місяці тому +1

      Sorry about that!!

  • @CharlesMurphy1000
    @CharlesMurphy1000 Місяць тому

    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!

  • @khadijaashraf
    @khadijaashraf Місяць тому

    awesome visualization! would love to see the O(1) space solution too.

  • @shivamguys
    @shivamguys 2 місяці тому +1

    Love the way you explain

  • @jassemtoumi2876
    @jassemtoumi2876 5 місяців тому +2

    Great Explanation !! keep it up

  • @NSSanya
    @NSSanya Місяць тому

    very nice explanation! cheers

  • @X3Maverick
    @X3Maverick 4 місяці тому +11

    Seems like you should take "2 Pointers" out of the video title.

    • @GregHogg
      @GregHogg  4 місяці тому +1

      Nah, that's the name of the algorithm

    • @X3Maverick
      @X3Maverick 4 місяці тому +12

      ​@@GregHogg No, this is a 1 pointer solution. The solution you allude to at the end of the video is a 2 pointer solution.

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

    if you were not going to show 2 pointers then why did you have it in the title.

  • @tanmaysharma3908
    @tanmaysharma3908 Місяць тому

    heyy man! great work, i love you!!!

  • @malakggh
    @malakggh Місяць тому

    Thank you for saying it's stupidity hard 😂😂

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

    Thank man, it is really helpful keep up the Good work. ☺

  • @nandepucharitha9049
    @nandepucharitha9049 7 місяців тому +1

    thanks man

    • @GregHogg
      @GregHogg  7 місяців тому +1

      My pleasure, thank you so much for your support!

  • @anandreddy1976
    @anandreddy1976 2 місяці тому +1

    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 3 місяці тому +5

    This is not an optimal solution, and you are misguiding

    • @AdityaRaj-lj5wf
      @AdityaRaj-lj5wf 3 місяці тому +1

      this was not two pointers technically

  • @GeraudKAMENI
    @GeraudKAMENI Місяць тому

    This is not the best solution, and it's not a two-pointer approach either!!