Practice: Swim in Rising Water
Problem: https://leetcode.com/problems/swim-in-rising-water/
Recognition reminder: the grid is a weighted graph in disguise (Week 11’s “grids are graphs”, now with weights). Water rises over time, and at time t you can stand on any cell whose elevation is at most t. You want the earliest time you can get from the top-left to the bottom-right. The twist that makes this an advanced-graph problem: the “cost” of a path is not the sum of the cells you cross, it is the maximum elevation along it, because that single highest cell is what you must wait for the water to reach. So you are minimizing the largest cell on a path from corner to corner. Think about how the usual relaxation step changes when the path cost is a max rather than a sum (and, separately, whether you could instead guess a time t and ask “is the destination reachable using only cells at most t”, then search over t).
Before you start (the five-beat rhythm)
- Your Pattern Card for this week is already written.
- Name the pattern aloud and write your approach as a plain-English comment before any code.
- Struggle floor: 25 minutes unaided. No hints, no AI, no Discuss tab.
- If stuck past the floor, ask the tutor for a hint. Six rungs, one per ask.
- Debrief in your commit message before moving to the next problem.
Your target
Fill these in yourself before you look at anyone else’s solution:
Target time complexity: ____
Target space complexity: ____
There are two clean approaches, and they reach the same complexity from different directions. Express your target in terms of the grid side length n, and be ready to say which approach you chose and why.
Where your code goes
Write your solution in your own work repo (see getting-started.md), not in this folder. This folder ships only the problem spec and a provided-example test (tests/test_provided.py) so you can check the given cases locally before you submit to LeetCode’s judge. The judge is the oracle; the tutor will not confirm your answer by reading it.
Debrief (paste into your commit message)
1. What pattern did this turn out to be?
2. What was the trigger phrase or input shape that should have made me reach for it?
3. What was the time and space complexity, and what would dominate at scale?
4. What edge case would have broken my first attempt?
5. What would I do differently in three days when I see this cold?