In an n×n grid, at time t you can swim to adjacent cells with elevation ≤ t. Find the minimum time to reach bottom-right from top-left. This is modified Dijkstra where 'distance' is the max elevation along the path.
Use a min-heap. The cost to reach a cell = max(cost to reach current, elevation of neighbor). We want to minimize the maximum elevation.
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
swimInWater(grid)
3