rows rows and cols columns, both numbered from 1. On day 0 the whole field is dry land. After that, one cell goes under water each day: on day i (counting from 1) the cell flooded[i - 1] = [r, c] floods, meaning row r, column c. Every cell floods exactly once.
A traveller wants to walk on dry land from any cell of the top row to any cell of the bottom row, moving only up, down, left or right.
Return the last day such that, once that day's cell has flooded, the walk is still possible.rows=2, cols=3, flooded=[[1, 2], [2, 1], [2, 3], [1, 1], [2, 2], [1, 3]] → 2
After day 2 the dry cells are (1,1), (1,3), (2,2), (2,3), and you can step down from (1,3) to (2,3). On day 3 (2,3) floods and no path is left. The answer is 2.
rows=2, cols=2, flooded=[[1, 1], [1, 2], [2, 1], [2, 2]] → 1
By day 2 the whole top row is under water, so the last dry day is day 1.
flooded are distinctrows=2, cols=3, flooded=[[1, 2], [2, 1], [2, 3], [1, 1], [2, 2], [1, 3]]
2
Run checks the first 3 tests in your browser. Submit checks all 37 tests on the server, hidden ones included.