Last Dry Crossing
A field has rows rows and cols columns and starts out dry. Then the water comes: on day 1 the cell floods[0] goes under, on day 2 the cell floods[1], and so on. Each entry is [row, column], and a flooded cell stays flooded.
You can cross the field if you can walk from some cell of the top row to some cell of the bottom row over dry cells, moving up, down, left or right.
Return the last day at the end of which you can still cross. Day 0 is the dry field before any flooding.
Example 1
After day 2 the right column is still dry from top to bottom. Day 3 closes the middle row.
Example 2
Day 2 leaves one dry cell in each row, and the two do not touch.
Example 3
The left column stays dry, so the answer is the last day there is.
Constraints
1 <= rows <= 12and1 <= cols <= 12floodsholds different cells of the field, at mostrows * colsof them
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.