Minimum Number of Days to Disconnect Island | Studied Concept | Leetcode 1568 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 103rd 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 : Minimum Number of Days to Disconnect Island | Already Studied Concept | Easy Code | Leetcode 1568 | codestorywithMIK
This can be more efficiently solved using "Tarjan's Algorithm". I will soon make a video on Tarjan and will then make a video for this problem using Tarjan.
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 : Minimum Number of Days to Disconnect Island | Already Studied Concept | Easy Code | Leetcode 1568 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/minimum...
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 :
The approach above uses Depth-First Search (DFS) to determine the minimum number of days required to disconnect all land cells (represented by 1s) in a grid. The problem is treated as finding the number of "islands" in the grid, where an island is defined as a group of connected land cells.
Steps:
DFS Implementation:
The DFS function explores all connected land cells starting from any unvisited cell. It marks cells as visited to avoid reprocessing.
Counting Islands:
The numberOfIslandsDFS function uses DFS to count the number of islands in the grid. This is done by iterating through all cells in the grid and initiating a DFS whenever an unvisited land cell is found.
Determining Minimum Days:
Initially, the function checks if the grid is already disconnected (i.e., has more than one island or no islands). If so, the answer is 0 days.
If the grid is still connected, the function then checks whether removing a single land cell can disconnect the grid. If a single removal causes disconnection, the answer is 1 day.
If neither of the above conditions is met, the grid can always be disconnected in 2 days by removing two cells.
This approach efficiently determines the minimum number of days required by leveraging DFS for island detection and simulating cell removal.
✨ 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