Number of Islands | DFS | BFS | Same as Island Perimeter | Leetcode 200 | codestorywithMIK

preview_player
Показать описание
This is the 91st Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a very good 2D Array problem : Number of Islands | DFS | BFS | Same as Island Perimeter | Leetcode 200 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Number of Islands | DFS | BFS | Same as Island Perimeter | Leetcode 200 | codestorywithMIK
Company Tags : Paytm, Amazon, Microsoft, Samsung, Snapdeal, Citrix, D-E-Shaw, Ola Cabs, Visa, Linkedin, Opera, Streamoid Technologies, Informatica

Approach Summary :
Approach-1 (DFS):
- Time Complexity (T.C) : O(m*n), where m is the number of rows and n is the number of columns in the grid.
- Space Complexity (S.C): O(1)
- Summary: In this approach, Depth-First Search (DFS) algorithm is used to traverse the grid. The algorithm checks each cell of the grid. If a cell contains '1', indicating it's a part of an island, DFS is recursively called to mark all adjacent '1's as visited. This process continues until all cells of the current island are visited. Finally, the algorithm counts the number of islands by iterating through all cells of the grid.

Approach-2 (BFS):
- Time Complexity (T.C) : O(m*n), where m is the number of rows and n is the number of columns in the grid.
- Space Complexity (S.C): O(1)
- Summary: This approach utilizes Breadth-First Search (BFS) algorithm to traverse the grid. It iterates through each cell of the grid. If a cell contains '1', indicating it's a part of an island, BFS is performed to explore all neighboring '1's and mark them as visited. The algorithm continues this process until all cells of the current island are visited. Finally, the algorithm counts the number of islands by iterating through all cells of the grid.

Both approaches have the same time and space complexities, making them efficient solutions for finding the number of islands in a given grid.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
06:48 - Approach-1 & Approach-2 Explanation
12:14 - Coding DFS
14:55 - Coding BFS

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
Рекомендации по теме
Комментарии
Автор

You know you understand the logic when you get the intuition at 6:30 Thanks for this amazing tutorial, also the way you explained yesterday's question "Island Perimeter" made this question a cake walk.

thor
Автор

amazing sir
dheere dheere apke solution dheke problem ko approach karna sikh rha hu
keep it up sir 🙂

detaincoder
Автор

Mik is just reducing his watch time by teaching so brilliantly lol.

thor
Автор

could solve this on my own, thanks to you

varunsen
Автор

bhai duniya ke saare question upload krdo nn, it becomes really painful jab koi question smjh na aa rha ho and then there's no solution from your side.

Shubham-kk
Автор

Bro I solved the problem "number of distinct Islands" on my own.
is there any reward ??😊😎🙏

manimanohar_
Автор

In every video you say "Medium Mark h bilkul easy h" and in case hard problem "hard Mark h but medium h"😂😂

Ramgangakumar
Автор

Bro there's a question named "Number of Distinct Islands" in both LC & GFG.
But in LC it's a premium question.

molyoxide
Автор

iske liye koi simplest approach nahi hai, like the iterative approach?

aizadiqbal
Автор

Bhaiya "Find unique island" ka question kha per hai, leetcode me to nhi dikh rha hai.

singhshek
Автор

public int numIslands(char[][]grid){
int cnt=0;
for(int i=0;i<grid.length;i++)
for(int j=0;j<grid[0].length;j++)
if(grid[i][j]=='1'){
dfs(grid, i, j);
cnt++;
}
return cnt;
}
private void dfs(char[][]grid, int i, int j){
return;
grid[i][j]='2';
dfs(grid, i+1, j);
dfs(grid, i-1, j);
dfs(grid, i, j+1);
dfs(grid, i, j-1);
}
}
🎉❤

dayashankarlakhotia
Автор

Bro there's no question like "Find Unique Islands". Pls give the question link

molyoxide