Google Coding Question - Making a Large Island (Hard)

  Рет қаралды 15,700

AlgosWithMichael

AlgosWithMichael

Күн бұрын

Here is a step by step explanation of a Google coding question involving DFS/BFS rated as hard!
Check out my interview prep platform for learning the patterns!
📢 Interview Prep Platform: algoswithmichael.com
►Number of Islands Explanation Video: • Technical Interview Qu... `
🎧 Join the community Discord: / discord
💰 Support me on Patreon: / michaelmuinos
🔗Follow me on LinkedIn: / michael-muinos
📂Follow me on Github: github.com/MichaelMuinos
This is another video explanation going over the infamous "island" problems called "Making a Large Island". This problem is asked at Google and involves the use of a Breadth-First Search OR Depth-First Search. This problem is rated as "hard".
To solve this problem, we must first loop over our initial 2D matrix filled with 0's (water) and 1's (land). We keep track of the groupings of islands using an 'islandId' in order to label the appropriate sizes of the islands. We then save these island id's inside of map and tie the island size to it.
Once we are finished tallying up all of the sizes of the islands inside of the map, we can now iterate over our 2D matrix again, but this time checking all neighbors around only 0's to determine if changing it to a 1 will allow for a larger island size.
The time and space complexity for our solution is O(N^2) where N is the number of elements we have in our 2D matrix.

Пікірлер: 95
@samyakkumarsahoo8706
@samyakkumarsahoo8706 2 жыл бұрын
Every struggling coder needs a mentor like you.
@seanvance3393
@seanvance3393 2 жыл бұрын
Instablaster
@stephandowless1297
@stephandowless1297 2 жыл бұрын
this guy does such a great job of breaking complex problems down into simple steps. goes very in depth with examples as well. great job
@TheSkyCries1
@TheSkyCries1 2 жыл бұрын
You are the man. I spent all day doing this problem, but thanks to you, I actually understand it now. I can't tell you how much I appreciate you.
@fk121276
@fk121276 3 жыл бұрын
Thank you Michael Muinos. Simply the best explainations, when I search I first see if I find a video from Michael Muinos, if not then from Tushar Roy, if not then whatever I get.
@pradnyeshchoudhari9376
@pradnyeshchoudhari9376 2 жыл бұрын
Best and easiest solution that I could ever find for the problem. Thank You!!
@darthvader_
@darthvader_ 3 жыл бұрын
The best part about his explanation is he cuts to the chase, where others are engaged in explaining things he has already arrived at the coding part!
@RajeevKumar-xz2zr
@RajeevKumar-xz2zr 3 жыл бұрын
nicely done! before watching this I watced few other videos but couldn't get anything. 11 minutes of your video and everything was crystal clear.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Great to hear!
@KushalBhatia
@KushalBhatia 2 жыл бұрын
Thank you for patiently going through the whole grid instead of just saying so and so and moving to code. Amazing explanation
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
You're very welcome!
@wendyzhou7618
@wendyzhou7618 2 жыл бұрын
super clear, right on the point. feel so lucky that I ran into this video, thanks!
@pleasedontsubscribeme4397
@pleasedontsubscribeme4397 2 жыл бұрын
Crystal clear explanation, I being a noob coded the solution with your thought process. Thanks!
@salmanuddin3779
@salmanuddin3779 8 ай бұрын
Such a great explanation , I was able to understand every bit of it. Thank you 💛
@RishabhJain-hr6sz
@RishabhJain-hr6sz 2 жыл бұрын
Perfectly explained. Thank you!
@hoyinli7462
@hoyinli7462 2 жыл бұрын
watching your video saved me tons of time. THX!
@kickradar3348
@kickradar3348 2 жыл бұрын
What an incredible solution! Thank you for this vid!
@shinansun9438
@shinansun9438 2 жыл бұрын
Great Video Michael. Very clear instructions
@Obligedcartoon
@Obligedcartoon 2 жыл бұрын
bloody brilliant mate
@lapujain
@lapujain 4 жыл бұрын
Amazing. Your way of explanation is awesome. Keep up the good work.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
I appreciate that, thank you!
@sagarsrivastava7728
@sagarsrivastava7728 Жыл бұрын
Excellent Explanation!!!
@leowu5058
@leowu5058 2 жыл бұрын
thank you for making all these great videos for us!
@mk-ec6px
@mk-ec6px 4 жыл бұрын
This is lit 🔥 please do more graph problems
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thanks dude, will do!
@nehashinde6017
@nehashinde6017 2 жыл бұрын
You made it so easy!!!! Thank you so much!
@plvshy
@plvshy 2 жыл бұрын
Awesome explanation, thank you!
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
Best explanation for this problem
@chandandigumarthy9652
@chandandigumarthy9652 2 жыл бұрын
Amazing man ! your explanations made it soo easy to understand, thanks
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
Glad it helped!
@Dinesh-ti6ql
@Dinesh-ti6ql 3 жыл бұрын
Most satisfying code ever watched😌 keep up the work dude✌
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you, will do!
@andrewthmas
@andrewthmas 3 жыл бұрын
Thanks man. You understand what you are doing.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
I appreciate that!
@momoX7777
@momoX7777 3 жыл бұрын
AMAZING EXPLAINATION!!!
@anuragsekhri2315
@anuragsekhri2315 2 жыл бұрын
well explained. thanks a lot
@amritanshu83
@amritanshu83 2 жыл бұрын
Awesome explanation dude..so well explained. This is how solutions should be made. Keep up the good work!
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
Thanks, will do!
@aayushsrivastava9569
@aayushsrivastava9569 2 жыл бұрын
Great explanation thanks !!
@rakeshgupta8901
@rakeshgupta8901 3 жыл бұрын
One of the best explanation I seen
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you!
@jamsrandorjbatbayar3652
@jamsrandorjbatbayar3652 2 жыл бұрын
great explanation, much appreciated!
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
No problem!
@supratim08
@supratim08 2 жыл бұрын
Great explanation bro ❤😌
@shruthib3366
@shruthib3366 2 жыл бұрын
This algo literally blew my mind!
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
Haha yeah it is pretty crazy
@yy-gf7ze
@yy-gf7ze 2 жыл бұрын
Michale is THE BEST.
@roxanamoghbel9147
@roxanamoghbel9147 2 жыл бұрын
your videos are the best
@code7434
@code7434 4 жыл бұрын
Really loved the explaination
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you, I'm glad it was helpful!
@AnuragBaidyanath
@AnuragBaidyanath 3 жыл бұрын
GG Michael! Clear explanation. :)
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Glad it was helpful!
@Arun1995plus1
@Arun1995plus1 2 жыл бұрын
Thank you 🙏🏾
@NithinMWarrier
@NithinMWarrier 3 жыл бұрын
Thanks Michael, you explained very clearly with time and space complexity. One suggestion is to use proper variable names eg. instead of x, y, newRow, newColumn would be better, good job, keep going bro..
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Great suggestion!
@shoyohinata1612
@shoyohinata1612 2 жыл бұрын
Dude you are great..!!
@angelsancheese
@angelsancheese 2 жыл бұрын
thank you for the video
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
No worries!
@ayonkar1534
@ayonkar1534 4 жыл бұрын
Clear-cut Amazing
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you!
@justgame5508
@justgame5508 2 жыл бұрын
With some of these hard probables you can get trapped down rabbit holes, trying to solve the problem when you don t fully understand the question, a pen and paper or white board makes them so much easier you can draw things out and quickly see and issues with logic you may otherwise had assumed was sound
@evanliu6158
@evanliu6158 3 жыл бұрын
Cool! Your explanation cured my panic.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Nice!
@xeri_zarek
@xeri_zarek 3 жыл бұрын
Thanks for these videos! I've been looking all over for straightforward walkthroughs of algorithms + code for this type of problem, and yours are by far the most helpful I've found :) I did want to ask, why is the time complexity O(N^2)? since the loops you highlighted aren't nested, shouldn't it be O(2 * N) which is just O(N)? Or does the recursion in the getIslandSize method factor into the calculation?
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Of course, thank you for watching! Looping over a grid will be n * m. If the columns and rows are the same, it is n2.
@user-Sjskakendjsiwjd
@user-Sjskakendjsiwjd 3 жыл бұрын
I was initially a bit confused about this too because he said N is the number of items inside the input array, which then should be O(N).
@mengjiasings1278
@mengjiasings1278 2 жыл бұрын
I was trying to submit this LC but couldn't get anything. You saved my day:)
@sanjayizardar2263
@sanjayizardar2263 4 жыл бұрын
Very helpful 👍
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Glad I could help!
@kumarc4853
@kumarc4853 3 жыл бұрын
Very KIND of you :p
@himanshuchhikara4918
@himanshuchhikara4918 3 жыл бұрын
best explanation
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you!
@joann4369
@joann4369 2 жыл бұрын
how would you explain further why the space complexity os O(N^2)?
@amritgupta5703
@amritgupta5703 4 жыл бұрын
Please make similar videos of interview hot problems. Focus on algorithm like this video so that we C++ people can code easily in our way after getting algorithm.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Definitely will!
@edwardteach2
@edwardteach2 2 жыл бұрын
U the Goat
@sara1khan157
@sara1khan157 3 жыл бұрын
nice explanation . one doubt : if no of rows = n , no of cols = n , then getIslandSize -- is dfs call --- it will take O (n^2) which is equal to no of nodes traversed _ outer loop is also n^2 so total time complexity is O (n^4) Please correct me if I misunderstood Thanks
@sara1khan157
@sara1khan157 3 жыл бұрын
got it please ignore the question :)
@FaustoOliveiraFilho
@FaustoOliveiraFilho 3 жыл бұрын
Really good, man! Your didactics is incredible! You should get yourself a pen; it will make your drawings much easier and better than your mouse.
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you very much! Actually all of my newer videos are animated now, no more drawing with a mouse haha
@FaustoOliveiraFilho
@FaustoOliveiraFilho 3 жыл бұрын
@@AlgosWithMichael I have 18 years of experience as a developer and now I'm practicing for an interview at Amazon. Your videos are really handy and your explanation comprehensive without being dull. Thank you for all your efforts!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
No problem at all, I wish you the best with your interviews!
@amritgupta5703
@amritgupta5703 4 жыл бұрын
This is LIT
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
🔥🔥🔥🔥 Thanks man haha
@code7434
@code7434 4 жыл бұрын
Shortest bridge is similar problem please cover it
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Definitely! Graph problems are the hardest imo
@saisriharshagriddaluru9261
@saisriharshagriddaluru9261 2 жыл бұрын
why grid[i][j] > 1 is wrong there? can any one explain?
@code7434
@code7434 4 жыл бұрын
Nice
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thanks!
@kaushaldawra3527
@kaushaldawra3527 3 жыл бұрын
Is there a fan club I can join?
@shreejitnair2174
@shreejitnair2174 3 жыл бұрын
wow beautiful
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thanks a lot!