Number of Islands - LeetCode 200 Python

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024

Комментарии • 78

  • @chickaberga2
    @chickaberga2 3 года назад +16

    Did you come up with this solution yourself? Regardless, this is such a remarkable explantation/tutorial. This question got me during my Amazon interview

  • @sagittude123
    @sagittude123 3 года назад +16

    I would like to highlight the uniqueness in your video. Most videos on RUclips explaining Leetcode problems, either go over the solution on whiteboard, and then the coding and then they are done
    No explanation of how the algorithm runs using an example (if it runs), which is so important in interviews.
    You have done such a great job in going through the high level algorithm , the code and then how the code would run. That just set you apart! Thanks a lot and well done!

    • @DEEPTITALESRA
      @DEEPTITALESRA  3 года назад +3

      Ahhh thank you so much Sagar!!! :)))

    • @ugochukwustephenmbonu7974
      @ugochukwustephenmbonu7974 2 года назад +2

      that's exactly why I subscribed to her

    • @immabe_kind
      @immabe_kind Год назад +1

      just want to echo what @sagar mentioned. So true. Thank you Deepti!

  • @priyavardhanpatel6155
    @priyavardhanpatel6155 Год назад +2

    awesome thank you so much😍, it even helped me to optimize my solution for leetcode 733.

  • @aimie2837
    @aimie2837 3 года назад +2

    def got me during my google interview :(

  • @divyatalesra4767
    @divyatalesra4767 3 года назад +4

    Wow!! So helpful!!!! Thanks for the amazing explanation 😍😍😍

  • @scoobyy3112
    @scoobyy3112 8 месяцев назад +1

    This is such an amazing explanation!

  • @khoaanh7375
    @khoaanh7375 2 года назад +1

    Thank you so much . This is the solution I'm looking for to understand the depth-first search implementation in this problem.

  • @billmono9466
    @billmono9466 3 года назад +1

    Why the time complexity is only O(m*n)? Inside the nested loop, you call a function that iterates in the list, which should be O(m*n*dimension list)

  • @connornusser-mclemore631
    @connornusser-mclemore631 3 года назад +1

    How does grid change without a return statement

  • @anirudhraj3984
    @anirudhraj3984 2 года назад +1

    In short... best solutions for similar problem out there

  • @mdmasiud542
    @mdmasiud542 3 года назад +1

    beauty with brain

  • @raullopez3029
    @raullopez3029 2 года назад +1

    I watched multiple videos over this problems and you explained it the best. Thank you!!

    • @DEEPTITALESRA
      @DEEPTITALESRA  2 года назад

      Ah love hearing this helped thanks sm Raul!!:)

  • @augustinthesky
    @augustinthesky 2 года назад

    Can you please help me to count islands using Uniform Cost Search. It's my midterm assignment and i have no clue... :(((

  • @Drdoggo24
    @Drdoggo24 3 года назад +3

    Thanks so much!! Neat and clear explaination

  • @aricanadietv3795
    @aricanadietv3795 2 года назад +1

    I really like the way you explain each leetcode problem. Thank you!

  • @MIDNightPT4
    @MIDNightPT4 2 года назад +1

    You explained the recursion really well! Thanks

  • @randhivmalhotra8268
    @randhivmalhotra8268 2 года назад

    What is my mistake?
    def numIslands(self, grid):
    """
    :type grid: List[List[str]]
    :rtype: int
    """
    if grid ==None or len(grid)==0 :
    return -1
    def dfs(grid,Rw,Cw,r,c):
    grid[r][c] = '0'
    for i in range(4):
    r+=dr[i]
    c+=dc[i]
    if r>=0 and r=0 and c

  • @luca8834
    @luca8834 3 года назад +1

    I've never commented on anyone's video but your video really helped me understand the question well. Great work and I hope to see more videos from you!

  • @Nirmaloff
    @Nirmaloff 2 года назад +1

    Finally, I got came to the correct place wow!!!! what a clear explanations love your explanation

  • @rhapsody9442
    @rhapsody9442 2 года назад +1

    Excellent explanation! I've stuck with this problem for a whole day. Your video helped me a lot. Thank you!

  • @kazeemkz
    @kazeemkz 2 года назад +1

    Fantastic delivery, I must admit. I battled with this question for hours. Many thanks.

  • @asgm1382
    @asgm1382 2 года назад +1

    Beautiful explanation, please make more videos you are amazing at explaining. Great video :D

  • @shivaexerciseshealthyrecip2723

    hi ,
    recursiom error : maximum depth exceeded in comparison

  • @emmawu8137
    @emmawu8137 3 года назад +1

    Best answer! Thx!

  • @MrRenaissance17
    @MrRenaissance17 2 года назад +1

    I love how you broke this down I was confused at first but after watching it again I understood what you were doing. Great Video.

    • @DEEPTITALESRA
      @DEEPTITALESRA  2 года назад

      Love hearing this thanks so much!!:)

  • @manpreetkour2345
    @manpreetkour2345 2 года назад +1

    You are just wow! I love the way you explain things. This is what we actually need.

  • @leomiao5959
    @leomiao5959 2 года назад +1

    The way you explain it is so detailed and informative, very good! Thank you~

  • @daniyalkabir6527
    @daniyalkabir6527 2 года назад +1

    This solution was super intuitive and helpful! Thank you so much!

  • @sashimi3637
    @sashimi3637 3 года назад

    how would you convert this dfs to bfs?

  • @manishpatil1949
    @manishpatil1949 3 года назад +1

    By far the best explanation!

  • @sahilmakwane5115
    @sahilmakwane5115 2 года назад

    Same solution for me exceeded memory

  • @williamleratakis7667
    @williamleratakis7667 3 года назад +1

    Thank you!

  • @axscs1178
    @axscs1178 2 года назад

    how would one go about counting islands in the special case the island HAS to be a rectangle?

  • @monikajavadi1274
    @monikajavadi1274 3 года назад +1

    Such a great explanation, thanks!:)

  • @aaditya_87
    @aaditya_87 Год назад

    everything is perfect except its not that intuitive

    • @DEEPTITALESRA
      @DEEPTITALESRA  Год назад

      yea def at first if you aren't used to thinking this way/solving these problems it can def seem out of the box. But once you start doing more of these problems, it'll become not only intuitive, but super easy Aditya!!:))

  • @samCoder
    @samCoder 3 года назад

    Great Explaining. I was literally looking for an explaination in Python and I found your channel.
    Great Deepti! I subscribed to the channel!!

  • @jonparicien316
    @jonparicien316 3 года назад

    I've been stressing about this question for the past week or so... you made it seem so simple!!!!! THANKS A BILLION

  • @aniketninawe1228
    @aniketninawe1228 3 года назад +1

    awesome

  • @Lexi-by8zd
    @Lexi-by8zd 3 года назад

    Thank you. Your explanation was very helpful!

  • @04mfjoyce
    @04mfjoyce 3 года назад

    Excellent explanation, thank you very much!

  • @balajiravindran2228
    @balajiravindran2228 3 года назад

    Thank you so much.. Well explained...

  • @sulaymanali8080
    @sulaymanali8080 3 года назад

    reallllly great explanation thank you

  • @kushagrasen1848
    @kushagrasen1848 3 года назад

    amazing dude.. an amazing explanation...

  • @muddasirkhan805
    @muddasirkhan805 3 года назад

    great stuff! very confident! Any resources you recommend that helped you gain the mastery of coming up with logic? thanks

    • @DEEPTITALESRA
      @DEEPTITALESRA  3 года назад +2

      Thanks so much Muddasir! Honestly just more practice - the more problems I did the easier it was to come up with logical formulation!:)

  • @jeffnguyen91
    @jeffnguyen91 3 года назад

    I thought with the double for loop it would make it O(N^2) ?

    • @DEEPTITALESRA
      @DEEPTITALESRA  3 года назад +1

      Hey Jeff! By the double for loop, do you mean the one in the function as well as the helper function? 
If so I can def explain more in-depth about that! :)
      Essentially for time complexity, we have an m x n array where m is the number of rows and n is the number of columns. From this we know we have a total of m(n) cells and visit each one. Because of this, we can say that our time complexity is of order O(mn). Of course, it is possible that we have a group of islands that we visit and mark as seen, and later on, could also traverse over the same cell we had already marked. This makes it so that it is possible we visit one cell twice (first as an island to mark as "0", and then over the original traversal where we check for any "1" marked cells). The worst case for this - suppose that the entire grid is just 1’s - we mark the entire grid and still iterate over every single 0. This means we’ve gone over all of the m(n) cells twice. This however, is 2*m*n and still of the order O(mn)!
      Let me know if this helps or if your question was about something else - always happy to explain further!:)

    • @jeffnguyen91
      @jeffnguyen91 3 года назад

      Ahh I see now. I was thinking whenver there is a double for loop it would be a o(n^2) time complexity for example if you were to do a brute force solution for 2 sum. But in this case its not doing that. Thanks for the clarification !!@@DEEPTITALESRA

    • @DEEPTITALESRA
      @DEEPTITALESRA  3 года назад +1

      @@jeffnguyen91 ofc!! lemme know if you have any other questions!:)