filmov
tv
Number of Islands | DFS | BFS | Same as Island Perimeter | Leetcode 200 | codestorywithMIK
![preview_player](https://i.ytimg.com/vi/yYKGNW6Y7BA/maxresdefault.jpg)
Показать описание
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
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
Комментарии