You are given two integers, rows and cols, which represent the number of rows and columns in a
Initially, on day 0, the whole matrix will just be all 0s, that is, all land. With each passing day, one of the cells of this matrix will get flooded and, therefore, will change to water, that is, from 0 to 1. This continues until the entire matrix is flooded. You are given a 1-based array, water_cells, that records which cell will be flooded on each day. Each element water_cells[i]=[ri,ci] indicates the cell present at the rith row and cith column of the matrix that will change from land to water on the ith day.
We can cross any cell of the matrix as long as it’s land. Once it changes to water, we can’t cross it. To cross any cell, we can only move in one of the four water_cells, you are required to find the last day where you can still cross the matrix, from top to bottom, by walking over the land cells only.
Note: You can start from any cell in the top row, and you need to be able to reach just one cell in the bottom row for it to count as a crossing.
Constraints:
rows, cols ≤50rows × cols ≤2500water_cells.length == rows × colsrowscolswater_cells are unique.Our aim is to find the maximum number of days where we can cross a 1-based binary matrix, let’s say, matrix, while it is being flooded one cell at a time. We need to cross matrix from top to bottom using a continuous path consisting only of land cells. If, at any time, we encounter a series of connected water cells from the leftmost side of the matrix to its rightmost side that blocks our continuous path of land cells, we won’t be able to cross the matrix.
In our solution, we’ll look for a single component of connected water cells from the left to the right of matrix, on each day. Once encountered, we’ll return this day as the last day where we can still cross matrix.
Note: We are not subtracting 1 from our final answer, because, in the context of this problem, we are starting from day 0, so we don’t need to adjust the value of days.
Since we are required to find a series of connected water cells, we can consider the cells in the matrix to be vertexes in a graph—each vertex connected to its neighbors—and then try to identify
You are given two integers, rows and cols, which represent the number of rows and columns in a
Initially, on day 0, the whole matrix will just be all 0s, that is, all land. With each passing day, one of the cells of this matrix will get flooded and, therefore, will change to water, that is, from 0 to 1. This continues until the entire matrix is flooded. You are given a 1-based array, water_cells, that records which cell will be flooded on each day. Each element water_cells[i]=[ri,ci] indicates the cell present at the rith row and cith column of the matrix that will change from land to water on the ith day.
We can cross any cell of the matrix as long as it’s land. Once it changes to water, we can’t cross it. To cross any cell, we can only move in one of the four water_cells, you are required to find the last day where you can still cross the matrix, from top to bottom, by walking over the land cells only.
Note: You can start from any cell in the top row, and you need to be able to reach just one cell in the bottom row for it to count as a crossing.
Constraints:
rows, cols ≤50rows × cols ≤2500water_cells.length == rows × colsrowscolswater_cells are unique.Our aim is to find the maximum number of days where we can cross a 1-based binary matrix, let’s say, matrix, while it is being flooded one cell at a time. We need to cross matrix from top to bottom using a continuous path consisting only of land cells. If, at any time, we encounter a series of connected water cells from the leftmost side of the matrix to its rightmost side that blocks our continuous path of land cells, we won’t be able to cross the matrix.
In our solution, we’ll look for a single component of connected water cells from the left to the right of matrix, on each day. Once encountered, we’ll return this day as the last day where we can still cross matrix.
Note: We are not subtracting 1 from our final answer, because, in the context of this problem, we are starting from day 0, so we don’t need to adjust the value of days.
Since we are required to find a series of connected water cells, we can consider the cells in the matrix to be vertexes in a graph—each vertex connected to its neighbors—and then try to identify