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 :)
@shreejitnair21743 жыл бұрын
very elegant. This is a solution you can realistically come up with during a live interview than some fancy solutions on leetcode.
@AlgosWithMichael3 жыл бұрын
Exactly, I like this approach alot
@freeeager3 жыл бұрын
Thank you for this video! I couldn’t understand LeetCode's or any other explanation of LeetCode 694 (another island problem). Then, KZbin 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!!!
@AlgosWithMichael3 жыл бұрын
Thank you so much!
@krnal213 жыл бұрын
you always have the better explanations, compared to other channels. Thanks a lot and please keep doing these amazing videos
@AlgosWithMichael3 жыл бұрын
I really appreciate that, that is my main goal!
@abhisheksuryavanshi96753 жыл бұрын
Your channel is so underrated!
@AlgosWithMichael3 жыл бұрын
Thank you!!
@ChandraShekhar-by3cd2 жыл бұрын
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!
@AlgosWithMichael2 жыл бұрын
Glad you liked it!
@harshitpandey75213 жыл бұрын
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).
@emilyhuang1934 жыл бұрын
Great explanation! So much clearer than any of the explanations on LeetCode. Thank you for the awesome video!
@AlgosWithMichael4 жыл бұрын
Awesome, that is the goal! Thanks for watching
@tulipsmango2 жыл бұрын
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
@Eug98194 жыл бұрын
the clearest explanation i found on this problem! awesome content Michael!
@AlgosWithMichael4 жыл бұрын
Great to hear!
@niksgupta363 жыл бұрын
Can you please make a video of this Q solving with Union-Find method?
@yosri11992 жыл бұрын
AMAZING MAN, i hope i do well in my interview
@AlgosWithMichael2 жыл бұрын
Thanks, best of luck!
@followerOfChrist212-x5n3 жыл бұрын
Thanks for the clear explanation. Keep up the great work, really appreciate it!
@AlgosWithMichael3 жыл бұрын
Will do, thanks for watching!
@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 😂
@JRivero5 ай бұрын
So clear. Thank you very much
@salonigandhi48074 жыл бұрын
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
@sqirrelboy3 жыл бұрын
Yes, He compleely ignored this possibility
@sakshamsingh63513 жыл бұрын
i think it's the base condition when he's checking if the cell is 1, then return true
@sauravlogsvio18914 жыл бұрын
Nice explanation! Carry on. Waiting for more to come!! Cheers!
@AlgosWithMichael4 жыл бұрын
Thanks, will do!
@imranwahid98713 жыл бұрын
You are awesome man! Loved your way of explanation.
@AlgosWithMichael3 жыл бұрын
Thanks a ton!
@ajaysukumar36424 жыл бұрын
Thanks mate, you made it really easy to understand
@AlgosWithMichael4 жыл бұрын
No problem 👍
@architshinde39773 жыл бұрын
Thank you so much for this video! Very helpful!
@AlgosWithMichael3 жыл бұрын
You are so welcome!
@karankanojiya76722 жыл бұрын
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);
@nishantduttmishra92902 жыл бұрын
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-r6y2 жыл бұрын
@@nishantduttmishra9290 Thank-you for answering the question! this helped me a lot
@sqirrelboy3 жыл бұрын
What if there is a 0 on the perimeter that makes the island not closed???!!?!
@aryamantodkar37163 жыл бұрын
Good Explanation! Thanks :)
@AlgosWithMichael3 жыл бұрын
No problem!
@rushrukhrayan10824 жыл бұрын
Thanks man! After the full length example, I was able to solve it :D
@AlgosWithMichael4 жыл бұрын
Nice! Example walkthroughs are the key to understanding these problems
@rushrukhrayan10824 жыл бұрын
Indeed. I just hope that by upsolving these questions I get to tackle similar problems by myself!
@AlgosWithMichael4 жыл бұрын
The more you do it, the easier it will be. simple as that!
@stonecoldcold29414 жыл бұрын
Awesome Explanation dude
@AlgosWithMichael4 жыл бұрын
Thanks man!
@rajat15484 жыл бұрын
Another great explanation by you sir..... Thanks
@AlgosWithMichael4 жыл бұрын
Thank you for the kind words!
@joydeeprony892 жыл бұрын
smooth AF
@ankursuri38534 жыл бұрын
Excellent man! You are so cool!
@AlgosWithMichael4 жыл бұрын
Haha thanks man, appreciate it!
@aparnagopal52014 жыл бұрын
good explanation! you write neat code : )
@AlgosWithMichael4 жыл бұрын
I try! Thank you so much
@flashliqu2 жыл бұрын
you are pretty smart!
@srinish19934 жыл бұрын
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
@AlgosWithMichael3 жыл бұрын
Many months late on the reply, but nice job!
@indiancseresearch61092 жыл бұрын
great explanation ......
@yitingg79424 жыл бұрын
Thank you so much as always!
@AlgosWithMichael4 жыл бұрын
You are so welcome!
@yanansuninbayarea78053 жыл бұрын
Will it work for this case? grid=[[0,0,1,0,0], [0, 0, 0, 1, 0], [0, 1,1,1,0]]
@AlgosWithMichael3 жыл бұрын
I'm not sure, I would test it on LeetCode
@fahaad_abbadi2 жыл бұрын
brilliant
@P_Narendra2 жыл бұрын
Tc- (m*n) , Sc - (m*n)
@soumyadeeproy66114 жыл бұрын
Can we change that 0 to 1 instead of -1 ? I guess it work as well ?
@AlgosWithMichael4 жыл бұрын
Yea, I think it would work the same.
@code74344 жыл бұрын
Great
@AlgosWithMichael4 жыл бұрын
Thank you!
@coolbud85413 жыл бұрын
time complexity isn't m*n i feel coz there are 4 recursive calls so it would be 4^(mn) i believe
@tofahub2 жыл бұрын
Each node gets visited only once
@dingusagar2 жыл бұрын
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