Swim in Rising Water
Master this topic with zero to advance depth.
Swim in Rising Water
Find the minimum time t needed to reach the bottom-right from the top-left in a grid with elevations.
Examples
Input: [[0,2],[1,3]]
Output: 3
Approach 1
Level III: Union-Find (Threshold Connectivity)
Intuition
Sort all cells by elevation. Add cells to DSU one by one in increasing order of (elevation). Stop when top-left and bottom-right are in the same component.
⏱ O(N^2 \log N)💾 O(N^2)
Detailed Dry Run
Cells sorted by elevation: (0,0):0, (1,0):1, (0,1):2, (1,1):3. At t=3, (1,1) is added, connecting everything. Result=3.
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.