Count Sub Islands | Easiest Thought Process | Leetcode 1905 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=OeaEOoM-g98



Duration: 0:00
7,019 views
300


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 104th Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a simple 2D Array Problem : Count Sub Islands | Easiest Thought Process | Leetcode 1905 | codestorywithMIK
We will solve it using BFS and DFS. Your homework is to solve it using DSU also.
If you want to revise DSU -    • Disjoint Set Union | DSU | Graph Conc...  

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 : Count Sub Islands | Easiest Thought Process | Leetcode 1905 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/count-s...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

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

Summary :
Approach 1 (DFS)

Time Complexity (T.C.): O(m×n)
Space Complexity (S.C.): O(1) (excluding the recursion stack)
This approach uses Depth-First Search (DFS) to explore potential sub-islands in grid2. The idea is to traverse each land cell (grid2[i][j] == 1) and check if it corresponds to land in grid1. If it does, the DFS continues exploring all connected cells in four directions (down, up, right, left). Cells that are visited are marked to avoid reprocessing. If all the connected cells in grid1 and grid2 align (both contain land), then the island in grid2 is considered a sub-island. The algorithm iterates through all cells in the grid, triggering DFS when it encounters unvisited land. The space complexity does not account for the recursion stack, which can grow to a depth of O(m×n) in the worst case.

Approach 2 (BFS)

Time Complexity (T.C.): O(m×n)
Space Complexity (S.C.): O(m×n) (due to the queue)
This approach uses Breadth-First Search (BFS) to solve the same problem of identifying sub-islands. Instead of recursively exploring connected land, BFS uses a queue to iteratively visit all neighboring land cells. The method marks visited cells and checks if corresponding cells in grid1 are also land. The queue ensures that all connected land cells are processed in layers, moving outward from the initial cell. The BFS approach typically uses more space than DFS due to the need for a queue, which can grow proportionally to the number of cells being processed.


✨ Timelines✨
00:00 - Introduction


#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




Other Videos By codestorywithMIK


2024-09-08Leetcode Contest Qn-4 ka Khauf
2024-09-06Linked List in Binary Tree | Easy | Dry Run | Leetcode 1367 | codestorywithMIK
2024-09-05Delete Nodes From Linked List Present in Array | Simple | Dry Run | Leetcode 3217 | codestorywithMIK
2024-09-04Walking Robot Simulation | Detailed Simulation | Leetcode 874 | codestorywithMIK
2024-09-01Find the Student that Will Replace the Chalk | 2 Ways | Leetcode 1894 | codestorywithMIK
2024-09-01DSA Shorts with MIK - 2
2024-08-31Convert 1D Array Into 2D Array | 2 Approaches | Leetcode 2022 | codestorywithMIK
2024-08-30Palindrome Partitioning II | Using Blue Print | DP On Strings | Leetcode 132 | DP Concepts & Qns-28
2024-08-30Modify Graph Edge Weights | Using Dijkstra | Thought Process | Leetcode 2699 | codestorywithMIK
2024-08-29Most Stones Removed with Same Row or Column | Using DSU | DRY RUN | Leetcode 947 | codestorywithMIK
2024-08-27Count Sub Islands | Easiest Thought Process | Leetcode 1905 | codestorywithMIK
2024-08-25Travel Tales
2024-08-24Find the Closest Palindrome | Simple Observations | Leetcode 564 | codestorywithMIK
2024-08-22Fraction Addition and Subtraction | Simple Simulation | Leetcode 592 | codestorywithMIK
2024-08-22DSA Shorts with MIK - 1
2024-08-22Number Complement | Multiple Approaches | Leetcode 476 | codestorywithMIK
2024-08-192 Keys Keyboard | Detailed Explanations | Leetcode 650 | codestorywithMIK
2024-08-18Count Substrings That Satisfy K-Constraint I & II | Detailed Explanation | Leetcode 3258 & 3261
2024-08-16Maximum Number of Points with Cost | Detailed Explanation | Leetcode 1937 | codestorywithMIK
2024-08-16The Imperial Delhi | Weekend Getaway | Luxury Stay | 5 Star hotel | WeekendWithMik
2024-08-15Maximum Distance in Arrays | Leetcode 624 | codestorywithMIK



Other Statistics

Counter-Strike: Source Statistics For codestorywithMIK

At this time, codestorywithMIK has 34,577 views for Counter-Strike: Source spread across 5 videos. Less than an hour worth of Counter-Strike: Source videos were uploaded to his channel, making up less than 0.10% of the total overall content on codestorywithMIK's YouTube channel.