The Last Day Where You Can Still Cross coding problem involves a grid that starts as all water (0) and gradually turns into land (1) as days pass. You are given a sequence of coordinates where land appears each day. You need to find the last day you can still walk from the top row to the bottom row using only land cells (moving 4-directionally).
This "Hard" problem is a favorite at Atlassian and Google because it tests complex graph traversal and search strategies. It can be solved using either Binary Search on the answer or Union Find. It evaluates your ability to model a dynamic environment where connectivity changes over time and your knowledge of advanced algorithms like BFS/DFS or Disjoint Set Union (DSU).
There are two main patterns: Binary Search + BFS/DFS, or Union Find.
2x2 grid. Days: 1: (1,1), 2: (2,2), 3: (1,2), 4: (2,1).
The most common mistake is using BFS/DFS for every single day, which results in O(Days * N * M) and is far too slow. Using Binary Search reduces this to O(log(Days) * N * M). Another mistake is incorrect grid initialization (1-indexed vs 0-indexed) or forgetting to handle the 4-directional movement constraints.
For "Union Find, Binary Search interview pattern" problems on grids, always consider processing the events in reverse. Many problems that involve "breaking connectivity" become much easier to solve with DSU when viewed as "forming connectivity" in reverse.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Swim in Rising Water | Hard | Solve | |
| Smallest Rectangle Enclosing Black Pixels | Hard | Solve | |
| Making A Large Island | Hard | Solve | |
| Path With Maximum Minimum Value | Medium | Solve | |
| Path With Minimum Effort | Medium | Solve |