Number of Islands | LeetCode 200 | Google Coding Interview Tutorial

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • Number of Islands solution: LeetCode 200
    Code and written explanation: terriblewhiteboard.com/number...
    Link to problem: leetcode.com/problems/number-...
    Buy Me a Coffee: www.buymeacoffee.com/terrible...
    AFFILIATE LINKS
    If you're interested in learning algorithms, these are great resources.
    💻 40% off Tech Interview Pro: techinterviewpro.com/terriblew...
    ⌨️ 20% off CoderPro: coderpro.com/terriblewhiteboard
    💲 All coupons and discounts 💲
    terriblewhiteboard.com/coupon...
    Number of Islands | LeetCode 200 | Google Coding Interview
    #numberofislands #leetcode #algorithms #terriblewhiteboard #codinginterview
    Click the time stamp to jump to different parts of the video.
    00:00 Title
    00:06 Problem readout
    00:58 Whiteboard solution
    07:42 Coding solution
    17:55 Result and outro

Komentáře • 40

  • @TerribleWhiteboard
    @TerribleWhiteboard  Před 4 lety +13

    If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

  • @ycchne
    @ycchne Před rokem

    the best explanation I’ve ever seen so far. Great work! Thank you

  • @heyyyyyworld
    @heyyyyyworld Před 2 lety

    Thank you for the tutorial! You're a great teacher.

  • @chiamakaojiyi7126
    @chiamakaojiyi7126 Před 3 lety

    Thank you. You just saved my life with this detailed video!

  • @colesiegel1922
    @colesiegel1922 Před 4 lety +11

    Great video can you please also review the time and memory complexity

  • @Jaffy.
    @Jaffy. Před 4 lety +7

    I love that you draw graphs in your videos to demonstrate. It makes it a lot easier to understand than just showing the code.

  • @stonecoldcold2941
    @stonecoldcold2941 Před 4 lety +14

    Wonderful explanation that I have ever listened to for 2d Array-based problem!

  • @user-ic2fx3yu3s
    @user-ic2fx3yu3s Před 2 lety

    beautiful awsome amazing explanation i love you I'm from a non-English speaking country and i'm not good at English but i can understand this

  • @seth_king_codes
    @seth_king_codes Před rokem

    fantastic explanation

  • @Ali-mc4le
    @Ali-mc4le Před 4 lety +13

    I am glad I found a very good explanation in JS. Thank you so much! Please keep making more!

  • @praison9104
    @praison9104 Před 4 lety +7

    Keep it up. Your explanations are simple and awesome!

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

    I have personally struggled with implementing BFS and DFS into code for more than half a year now, asking others for help, searching online for explanations, solutions, etc. and nothing helped me make any progress at all. Your explanation of this taught me how to do it in 20 minutes. Thank you so so much dude. You've helped me so much more than anyone else. Even professors in my university.

  • @gauravmahadik1245
    @gauravmahadik1245 Před 4 lety +17

    Amazing Explanation! I really understood the problem very well as well as the solution. Even though I code in Python as I understood your logic I was able to convert it from JS to Python and run it successfully! Thank You soo much for making a video explaining the problem and the solution along with the code. I will make sure to see all of your other videos and understand the logic and convert them to code in Python! Thanks a lot for taking out the time to make a video explaining everything. Helped me save a lot of time and understanding everything quickly within half an hour!

  • @RAJUBHAI-ww7em
    @RAJUBHAI-ww7em Před rokem

    Thanks mate

  • @jbphoto7
    @jbphoto7 Před 3 lety

    Thank you!

  • @Shiva-zy7jq
    @Shiva-zy7jq Před 3 lety +2

    Please make more videos. I have asked all my friends to subscribe to your channel

  • @adityasoni1207
    @adityasoni1207 Před 2 lety

    Awesome Video! I wonder why have we stopped creating content? ?is it because of time commitments? By the way, i loved the music at the start as well! Thanks again for this!

  • @cwagnello
    @cwagnello Před 4 lety +6

    When I solved this instead of using "i" and "j" for the nested for loop iterating over every element. I called them "row" and "column" respectively to make it a bit easier to understand.

  • @danieltannor6647
    @danieltannor6647 Před 4 lety +10

    Nice vid, you might also wanna include the space and time complexities

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 4 lety +7

      Thanks!

    • @datduong6520
      @datduong6520 Před 3 lety

      Is the time complexity O(m*n) (row x column), and space is O(n)? I am not sure about space complexity

    • @LintaSheelkumar
      @LintaSheelkumar Před 3 lety

      @@datduong6520 Why do you think space complexity is O(n) In my opinion it is just the space for storing the numofIslands which is an integer since we are modifying the matrix to keep track of visited

  • @andreiatrigueiro
    @andreiatrigueiro Před 3 lety

    Once again THANK YOU!!
    Following the same logic in Java :)
    class Solution {
    int row;
    int column;
    public int numIslands(char[][] grid) {
    if(grid == null || grid.length == 0){
    return 0;
    }
    int countIsland = 0;
    row = grid.length;
    column = grid[0].length;
    for(int r = 0; r < row; r++){
    for(int c = 0; c < column; c++){
    if (grid[r][c] == '1') {
    getNumberOfIslands(grid, r, c);
    countIsland++;
    }
    }
    }
    return countIsland;
    }
    private void getNumberOfIslands(char[][] grid, int r, int c) {
    if (r < 0 || c < 0 || r >= row || c >= column || grid[r][c] != '1'){
    return;
    }
    grid[r][c] = '0';
    getNumberOfIslands(grid, r + 1, c);
    getNumberOfIslands(grid, r - 1, c);
    getNumberOfIslands(grid, r, c + 1);
    getNumberOfIslands(grid, r, c - 1);
    }
    }

  • @LintaSheelkumar
    @LintaSheelkumar Před 3 lety

    Hi, Could you please include time and space complexities?

  • @cwagnello
    @cwagnello Před 4 lety +5

    Good video. One nit pick around 8:45 you called it 2 arrays and I think you meant to say 2d array.

  • @leongrin6348
    @leongrin6348 Před 2 lety

    The explanation is fantastic. But it would be even better if it explained better the recursive function, even though I understand it is not the main point of this problem.

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

    Loved the explanation, I wanted to ask a question though. The current TC is O(Elements). What happens in case we don't turn the island 0 and let it be 1. I know it will result in a bad time complexity because in worst case it will be O(Element^4) but as I am getting another error than TLE that is why I wanted to ask just in case to clarify what possibilities of Runtime error are present.

  • @johnstephen8041
    @johnstephen8041 Před 3 lety

    What is the time complexity of this algorithym?

  • @RAJUBHAI-ww7em
    @RAJUBHAI-ww7em Před rokem

    Hmmmm