Google Coding Question - Making a Large Island (Hard)

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • 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.
  • Věda a technologie

Komentáře • 95

  • @samyakkumarsahoo8706
    @samyakkumarsahoo8706 Před 3 lety +17

    Every struggling coder needs a mentor like you.

  • @TheSkyCries1
    @TheSkyCries1 Před 3 lety +3

    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.

  • @stephandowless1297
    @stephandowless1297 Před 3 lety

    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

  • @fk121276
    @fk121276 Před 3 lety +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.

  • @salmanuddin3779
    @salmanuddin3779 Před 9 měsíci

    Such a great explanation , I was able to understand every bit of it. Thank you 💛

  • @RajeevKumar-xz2zr
    @RajeevKumar-xz2zr Před 3 lety +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.

  • @pradnyeshchoudhari9376
    @pradnyeshchoudhari9376 Před 3 lety +2

    Best and easiest solution that I could ever find for the problem. Thank You!!

  • @KushalBhatia
    @KushalBhatia Před 2 lety +1

    Thank you for patiently going through the whole grid instead of just saying so and so and moving to code. Amazing explanation

  • @lapujain
    @lapujain Před 4 lety +4

    Amazing. Your way of explanation is awesome. Keep up the good work.

  • @wendyzhou7618
    @wendyzhou7618 Před 2 lety

    super clear, right on the point. feel so lucky that I ran into this video, thanks!

  • @mk-ec6px
    @mk-ec6px Před 4 lety +14

    This is lit 🔥 please do more graph problems

  • @darthvader_
    @darthvader_ Před 3 lety +1

    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!

  • @shinansun9438
    @shinansun9438 Před 2 lety

    Great Video Michael. Very clear instructions

  • @pleasedontsubscribeme4397

    Crystal clear explanation, I being a noob coded the solution with your thought process.
    Thanks!

  • @kickradar3348
    @kickradar3348 Před 2 lety

    What an incredible solution! Thank you for this vid!

  • @RishabhJain-hr6sz
    @RishabhJain-hr6sz Před 3 lety +1

    Perfectly explained. Thank you!

  • @hoyinli7462
    @hoyinli7462 Před 3 lety

    watching your video saved me tons of time. THX!

  • @leowu5058
    @leowu5058 Před 2 lety

    thank you for making all these great videos for us!

  • @chandandigumarthy9652
    @chandandigumarthy9652 Před 2 lety

    Amazing man ! your explanations made it soo easy to understand, thanks

  • @sagarsrivastava7728
    @sagarsrivastava7728 Před rokem

    Excellent Explanation!!!

  • @Dinesh-ti6ql
    @Dinesh-ti6ql Před 3 lety

    Most satisfying code ever watched😌 keep up the work dude✌

  • @plvshygirl
    @plvshygirl Před 2 lety

    Awesome explanation, thank you!

  • @amritanshu83
    @amritanshu83 Před 2 lety

    Awesome explanation dude..so well explained. This is how solutions should be made. Keep up the good work!

  • @Obligedcartoon
    @Obligedcartoon Před 2 lety +1

    bloody brilliant mate

  • @nehashinde6017
    @nehashinde6017 Před 2 lety

    You made it so easy!!!! Thank you so much!

  • @andrewthmas
    @andrewthmas Před 3 lety +1

    Thanks man. You understand what you are doing.

  • @jamsrandorjbatbayar3652

    great explanation, much appreciated!

  • @AnuragBaidyanath
    @AnuragBaidyanath Před 3 lety +1

    GG Michael! Clear explanation. :)

  • @supratim08
    @supratim08 Před 3 lety

    Great explanation bro ❤😌

  • @aayushsrivastava9569
    @aayushsrivastava9569 Před 3 lety

    Great explanation thanks !!

  • @anuragsekhri2315
    @anuragsekhri2315 Před 3 lety

    well explained.
    thanks a lot

  • @momoX7777
    @momoX7777 Před 3 lety

    AMAZING EXPLAINATION!!!

  • @roxanamoghbel9147
    @roxanamoghbel9147 Před 2 lety

    your videos are the best

  • @code7434
    @code7434 Před 4 lety

    Really loved the explaination

  • @rakeshgupta8901
    @rakeshgupta8901 Před 3 lety +1

    One of the best explanation I seen

  • @codestorywithMIK
    @codestorywithMIK Před 3 lety

    Best explanation for this problem

  • @yy-gf7ze
    @yy-gf7ze Před 2 lety

    Michale is THE BEST.

  • @shruthib3366
    @shruthib3366 Před 2 lety

    This algo literally blew my mind!

  • @xeri_zarek
    @xeri_zarek Před 3 lety +6

    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  Před 3 lety

      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 Před 3 lety

      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).

  • @Arun1995plus1
    @Arun1995plus1 Před 2 lety

    Thank you 🙏🏾

  • @shoyohinata1612
    @shoyohinata1612 Před 3 lety

    Dude you are great..!!

  • @evanliu6158
    @evanliu6158 Před 3 lety

    Cool! Your explanation cured my panic.

  • @NithinMWarrier
    @NithinMWarrier Před 3 lety

    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..

  • @mengjiasings1278
    @mengjiasings1278 Před 3 lety

    I was trying to submit this LC but couldn't get anything. You saved my day:)

  • @justgame5508
    @justgame5508 Před 2 lety

    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

  • @joann4369
    @joann4369 Před 2 lety

    how would you explain further why the space complexity os O(N^2)?

  • @sanjayizardar2263
    @sanjayizardar2263 Před 4 lety

    Very helpful 👍

  • @angelsancheese
    @angelsancheese Před 2 lety

    thank you for the video

  • @ayonkar1534
    @ayonkar1534 Před 4 lety +2

    Clear-cut Amazing

  • @edwardteach2
    @edwardteach2 Před 2 lety

    U the Goat

  • @kumarc4853
    @kumarc4853 Před 3 lety

    Very KIND of you :p

  • @saisriharshagriddaluru9261

    why grid[i][j] > 1 is wrong there? can any one explain?

  • @amritgupta5703
    @amritgupta5703 Před 4 lety

    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.

  • @himanshuchhikara4918
    @himanshuchhikara4918 Před 3 lety

    best explanation

  • @kaushaldawra3527
    @kaushaldawra3527 Před 3 lety

    Is there a fan club I can join?

  • @amritgupta5703
    @amritgupta5703 Před 4 lety

    This is LIT

  • @FaustoOliveiraFilho
    @FaustoOliveiraFilho Před 3 lety

    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  Před 3 lety +1

      Thank you very much! Actually all of my newer videos are animated now, no more drawing with a mouse haha

    • @FaustoOliveiraFilho
      @FaustoOliveiraFilho Před 3 lety

      @@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  Před 3 lety +1

      No problem at all, I wish you the best with your interviews!

  • @code7434
    @code7434 Před 4 lety

    Shortest bridge is similar problem please cover it

  • @sara1khan157
    @sara1khan157 Před 3 lety

    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

  • @code7434
    @code7434 Před 4 lety +1

    Nice

  • @shreejitnair2174
    @shreejitnair2174 Před 3 lety

    wow beautiful