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

  Рет қаралды 13,643

AlgosWithMichael

AlgosWithMichael

Күн бұрын

Пікірлер: 72
@umeshhbhat
@umeshhbhat 3 жыл бұрын
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.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Exactly, I like this approach alot
@freeeager
@freeeager 3 жыл бұрын
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!!!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you so much!
@krnal21
@krnal21 3 жыл бұрын
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 жыл бұрын
Your channel is so underrated!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you!!
@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!
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
Glad you liked 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).
@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
@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
@Eug9819
@Eug9819 4 жыл бұрын
the clearest explanation i found on this problem! awesome content Michael!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Great to hear!
@niksgupta36
@niksgupta36 3 жыл бұрын
Can you please make a video of this Q solving with Union-Find method?
@yosri1199
@yosri1199 2 жыл бұрын
AMAZING MAN, i hope i do well in my interview
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
Thanks, best of luck!
@followerOfChrist212-x5n
@followerOfChrist212-x5n 3 жыл бұрын
Thanks for the clear explanation. Keep up the great work, really appreciate it!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Will do, thanks for watching!
@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 😂
@JRivero
@JRivero 5 ай бұрын
So clear. Thank you very much
@salonigandhi4807
@salonigandhi4807 4 жыл бұрын
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
@sauravlogsvio1891
@sauravlogsvio1891 4 жыл бұрын
Nice explanation! Carry on. Waiting for more to come!! Cheers!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thanks, will do!
@imranwahid9871
@imranwahid9871 3 жыл бұрын
You are awesome man! Loved your way of explanation.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thanks a ton!
@ajaysukumar3642
@ajaysukumar3642 4 жыл бұрын
Thanks mate, you made it really easy to understand
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
No problem 👍
@architshinde3977
@architshinde3977 3 жыл бұрын
Thank you so much for this video! Very helpful!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
You are so welcome!
@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 жыл бұрын
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
@sqirrelboy
@sqirrelboy 3 жыл бұрын
What if there is a 0 on the perimeter that makes the island not closed???!!?!
@aryamantodkar3716
@aryamantodkar3716 3 жыл бұрын
Good Explanation! Thanks :)
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
No problem!
@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
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thanks man!
@rajat1548
@rajat1548 4 жыл бұрын
Another great explanation by you sir..... Thanks
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you for the kind words!
@joydeeprony89
@joydeeprony89 2 жыл бұрын
smooth AF
@ankursuri3853
@ankursuri3853 4 жыл бұрын
Excellent man! You are so cool!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Haha thanks man, appreciate it!
@aparnagopal5201
@aparnagopal5201 4 жыл бұрын
good explanation! you write neat code : )
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
I try! Thank you so much
@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 3 жыл бұрын
Many months late on the reply, but nice job!
@indiancseresearch6109
@indiancseresearch6109 2 жыл бұрын
great explanation ......
@yitingg7942
@yitingg7942 4 жыл бұрын
Thank you so much as always!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
You are so welcome!
@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
@fahaad_abbadi
@fahaad_abbadi 2 жыл бұрын
brilliant
@P_Narendra
@P_Narendra 2 жыл бұрын
Tc- (m*n) , Sc - (m*n)
@soumyadeeproy6611
@soumyadeeproy6611 4 жыл бұрын
Can we change that 0 to 1 instead of -1 ? I guess it work as well ?
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Yea, I think it would work the same.
@code7434
@code7434 4 жыл бұрын
Great
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you!
@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
Amazon Coding Interview Question - First Missing Positive (LeetCode)
20:47
Google Coding Question - Making a Large Island (Hard)
25:11
AlgosWithMichael
Рет қаралды 16 М.
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 3,1 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 10 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 93 МЛН
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 1,9 МЛН
Number of Closed Islands - Leetcode 1254 - Python
13:48
NeetCodeIO
Рет қаралды 16 М.
Google Coding Interview With A Facebook Software Engineer
49:59
Clément Mihailescu
Рет қаралды 945 М.
Technical Interview Question - Max Area of Island [LeetCode]
26:18
AlgosWithMichael
Рет қаралды 9 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
Google Coding Interview Question - Path With Maximum Gold (LeetCode)
17:24
Coding Interview Prep | 3 MUST KNOW Graph Problem Tips
13:27
AlgosWithMichael
Рет қаралды 18 М.
Amazon Coding Interview Question - Number of Distinct Islands
17:43
AlgosWithMichael
Рет қаралды 26 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 197 М.
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 362 М.
FAANG Coding Interview Question - Container With Most Water (LeetCode)
13:30
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 3,1 МЛН