Google Coding Interview Question - Number of Closed Islands (LeetCode)

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ธ.ค. 2024

ความคิดเห็น • 72

  • @freeeager
    @freeeager 3 ปีที่แล้ว +1

    Thank you for this video! I couldn’t understand LeetCode's or any other explanation of LeetCode 694 (another island problem). Then, TH-cam brought me here. Your explanation of LeetCode 1254 made me understand LeetCode 694!! LeetCode should hire you because you’re so talented at explaining solutions!!!

  • @umeshhbhat
    @umeshhbhat 3 ปีที่แล้ว +2

    One suggestion.
    In a recursive function, explain the recursive approach first then the base condition so that we can understand why exactly the base condition was written. Thanks for the video :)

  • @shreejitnair2174
    @shreejitnair2174 3 ปีที่แล้ว

    very elegant. This is a solution you can realistically come up with during a live interview than some fancy solutions on leetcode.

  • @krnal21
    @krnal21 3 ปีที่แล้ว +1

    you always have the better explanations, compared to other channels. Thanks a lot and please keep doing these amazing videos

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      I really appreciate that, that is my main goal!

  • @abhisheksuryavanshi9675
    @abhisheksuryavanshi9675 3 ปีที่แล้ว +1

    Your channel is so underrated!

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 2 ปีที่แล้ว

    Thanks a lot for such a great and in-depth explanation of the problem. Really appreciate the way you explained the complex problem in simpler manner!

  • @emilyhuang193
    @emilyhuang193 4 ปีที่แล้ว

    Great explanation! So much clearer than any of the explanations on LeetCode. Thank you for the awesome video!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Awesome, that is the goal! Thanks for watching

  • @Eug9819
    @Eug9819 4 ปีที่แล้ว

    the clearest explanation i found on this problem! awesome content Michael!

  • @followerOfChrist212-x5n
    @followerOfChrist212-x5n 3 ปีที่แล้ว

    Thanks for the clear explanation. Keep up the great work, really appreciate it!

  • @harshitpandey7521
    @harshitpandey7521 3 ปีที่แล้ว

    I believe the space complexity would be O(max(m,n)) and not O(m*n). This is because at the worst limit, we are going to have the recursion call stack depth as max(m,n).

  • @JRivero
    @JRivero 6 หลายเดือนก่อน

    So clear. Thank you very much

  • @ajaysukumar3642
    @ajaysukumar3642 4 ปีที่แล้ว

    Thanks mate, you made it really easy to understand

  • @yosri1199
    @yosri1199 2 ปีที่แล้ว

    AMAZING MAN, i hope i do well in my interview

  • @imranwahid9871
    @imranwahid9871 3 ปีที่แล้ว

    You are awesome man! Loved your way of explanation.

  • @sauravlogsvio1891
    @sauravlogsvio1891 4 ปีที่แล้ว

    Nice explanation! Carry on. Waiting for more to come!! Cheers!

  • @rushrukhrayan1082
    @rushrukhrayan1082 4 ปีที่แล้ว

    Thanks man! After the full length example, I was able to solve it :D

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Nice! Example walkthroughs are the key to understanding these problems

    • @rushrukhrayan1082
      @rushrukhrayan1082 4 ปีที่แล้ว

      Indeed. I just hope that by upsolving these questions I get to tackle similar problems by myself!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      The more you do it, the easier it will be. simple as that!

  • @stonecoldcold2941
    @stonecoldcold2941 4 ปีที่แล้ว

    Awesome Explanation dude

  • @architshinde3977
    @architshinde3977 3 ปีที่แล้ว

    Thank you so much for this video! Very helpful!

  • @aryamantodkar3716
    @aryamantodkar3716 3 ปีที่แล้ว

    Good Explanation! Thanks :)

  • @salonigandhi4807
    @salonigandhi4807 4 ปีที่แล้ว +1

    How are we checking that our island is indeed surrounded by 1's. In the above example what if the top bottom rows and left right columns were all zeroes

    • @sqirrelboy
      @sqirrelboy 3 ปีที่แล้ว

      Yes, He compleely ignored this possibility

    • @sakshamsingh6351
      @sakshamsingh6351 3 ปีที่แล้ว

      i think it's the base condition when he's checking if the cell is 1, then return true

  • @niksgupta36
    @niksgupta36 3 ปีที่แล้ว

    Can you please make a video of this Q solving with Union-Find method?

  • @tulipsmango
    @tulipsmango 2 ปีที่แล้ว

    why do you need to store left, right, up, down into varaibles instead of directly returning all of those dfs statements with && together. i know this doesn't work but haven't been able to figure out the reason. appreciate any help thank you

  • @rajat1548
    @rajat1548 4 ปีที่แล้ว

    Another great explanation by you sir.....
    Thanks

  • @karankanojiya7672
    @karankanojiya7672 2 ปีที่แล้ว

    Hi @Michael Muinos Excellent Solution. But I was having one doubt regarding the All 4 direction recursive call.
    Why does the below recursion call returns the wrong Answers? I think it should work similar to your left , right, up & down
    // code
    return isClosedIsland(grid,i,j-1) && isClosedIsland(grid,i,j+1) && isClosedIsland(grid,i-1,j) && isClosedIsland(grid,i+1,j);

    • @nishantduttmishra9290
      @nishantduttmishra9290 2 ปีที่แล้ว +1

      because when you are calling the function with and operator, if any function call returns false, the rest are not going to execute, and as a result all the results are not going to marked as -1.so again when you revisit the unmarked zero, it will return true, resulting in more no of closed island.

    • @MCL-r6y
      @MCL-r6y 2 ปีที่แล้ว

      @@nishantduttmishra9290 Thank-you for answering the question! this helped me a lot

  • @ankursuri3853
    @ankursuri3853 4 ปีที่แล้ว

    Excellent man! You are so cool!

  • @joydeeprony89
    @joydeeprony89 2 ปีที่แล้ว

    smooth AF

  • @indiancseresearch6109
    @indiancseresearch6109 2 ปีที่แล้ว

    great explanation ......

  • @flashliqu
    @flashliqu 2 ปีที่แล้ว

    you are pretty smart!

  • @srinish1993
    @srinish1993 4 ปีที่แล้ว

    I was struggling to solve this problem, but with your hint for the problem : 2:20, I was able to solve the problem completely.
    class Solution {
    public int closedIsland(int[][] grid) {
    int m = grid.length, n=grid[0].length;
    for(int i=0; i

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Many months late on the reply, but nice job!

  • @yitingg7942
    @yitingg7942 4 ปีที่แล้ว

    Thank you so much as always!

  • @aparnagopal5201
    @aparnagopal5201 4 ปีที่แล้ว

    good explanation! you write neat code : )

  • @sqirrelboy
    @sqirrelboy 3 ปีที่แล้ว

    What if there is a 0 on the perimeter that makes the island not closed???!!?!

  • @sto2779
    @sto2779 ปีที่แล้ว

    0:05 - I think I got a theory why six figure tech FANGG employees asking island questions, they probably miss their recent Hawaii trips... lol 😂

  • @fahaad_abbadi
    @fahaad_abbadi 2 ปีที่แล้ว

    brilliant

  • @yanansuninbayarea7805
    @yanansuninbayarea7805 3 ปีที่แล้ว

    Will it work for this case? grid=[[0,0,1,0,0], [0, 0, 0, 1, 0], [0, 1,1,1,0]]

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      I'm not sure, I would test it on LeetCode

  • @soumyadeeproy6611
    @soumyadeeproy6611 4 ปีที่แล้ว

    Can we change that 0 to 1 instead of -1 ? I guess it work as well ?

  • @code7434
    @code7434 4 ปีที่แล้ว

    Great

  • @P_Narendra
    @P_Narendra 2 ปีที่แล้ว

    Tc- (m*n) , Sc - (m*n)

  • @coolbud8541
    @coolbud8541 3 ปีที่แล้ว

    time complexity isn't m*n i feel coz there are 4 recursive calls so it would be 4^(mn) i believe

    • @tofahub
      @tofahub 2 ปีที่แล้ว

      Each node gets visited only once

  • @dingusagar
    @dingusagar 2 ปีที่แล้ว

    Sharing my solution without using -1 for tracking visits.
    class Solution:
    def closedIsland(self, grid: List[List[int]]) -> int:
    m = len(grid)
    n = len(grid[0])
    def isClosedIsland(i, j):
    if i < 0 or j = m or j >= n:
    return False // if it reaches here, that means land is touching to the edge
    if grid[i][j] == 1:
    return True // from this direction, water is covering before the land reaches the edge
    grid[i][j] = 1 // turning land into water to indicate visit
    left = isClosedIsland(i, j-1)
    right = isClosedIsland(i, j+1)
    up = isClosedIsland(i-1, j)
    down = isClosedIsland(i+1, j)
    return left and right and up and down

    count = 0
    for i in range(m):
    for j in range(n):
    if grid[i][j] == 0 and isClosedIsland(i, j ):
    count +=1

    return count