Swim in Rising Water
Expert Answer & Key Takeaways
A complete guide to understanding and implementing Union Find.
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.
Course4All Technical Board
Verified ExpertSenior Software Engineers & Algorithmic Experts
Our DSA content is authored and reviewed by engineers from top tech firms to ensure optimal time and space complexity analysis.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.