Skip to main content
Hard Union Find Medium frequency

Swim in Rising Water

Open on LeetCode

Approach Summary

Min-heap (Dijkstra-style): always expand the cell with the minimum elevation. Track the maximum elevation seen to reach (n-1, n-1).

How to Recognize This Pattern

  • "Minimum time/elevation to reach target — choose min-cost path"
  • Modified Dijkstra: cost = max elevation on the path

Complexity Analysis

Time Complexity

O(n² log n)

Space Complexity

O(n²)

Tags

Array Binary Search DFS BFS Union-Find Heap Matrix

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee