Skip to content

1568. Minimum Number of Days to Disconnect Island #303

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to consider the following steps:

Steps to Solve the Problem:

  1. Check Initial Connectivity: First, check if the grid is already disconnected by determining if there is more than one island in the grid. If it's already disconnected, return 0.

  2. Check If Single Removal Disconnects the Island: Iterate through each cell of the grid. Temporarily convert the cell from 1 to 0 (if it's 1) and check if the grid becomes disconnected by counting the number of islands. If converting a single cell disconnects the island, return 1.

  3. Two Day Disconnection: If no single cell conversion disconnects the island, then the grid can be disconnected by converting any two adjacent land cells. Therefore, …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jan 23, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants