You are given a grid with row rows and col columns. At the start (day 0), every cell is land (value 0). Each day, one specific cell becomes water (value 1). The order in which cells flood is given in the array cells, where cells[i] = [r, c] means that on day i, the cell at row r and column c turns into water.
Your task is to determine the last day on which it is still possible to travel from any cell in the top row to any cell in the bottom row, moving only through land cells and only in the four directions (up, down, left, right).
Return the maximum day index where such a path still exists.
Input: row = 3, col = 3 cells = [[1,3],[2,2],[3,1],[1,1],[1,2],[2,1],[3,3],[3,2],[2,3]]
Output: 2
Explanation:
A valid land path from top to bottom exists until day 2. After day 3, all possible routes become blocked by water.
Input: row = 1, col = 3 cells = [[1,2],[1,1],[1,3]]
Output: 0
Explanation:
On day 0, all cells are land, so crossing is possible. Once day 1 arrives, the middle cell floods and no top-to-bottom path can exist.
Accepted:
Submission: