Code RoomSwim in rising water
HardPrep Room Coding #865

Swim in rising water

CodingAlgorithms & data structuresSenior–Staff~35 min

You are given an n x n grid where grid[r][c] is the elevation of cell (r,c). At time t the water level is t, and you can be at cell (r,c) only if grid[r][c] <= t. From the top-left cell you may move to a 4-directionally adjacent cell instantly if both cells are below the current water level. Return the least time t at which you can reach the bottom-right cell. (Equivalently, minimize the maximum elevation along a path from corner to corner.)

Implement
swim_in_water(grid: list[list[int]]) → int
Examples
in[[[0,2],[1,3]]]out3
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[[0,2],[1,3]]]3not run yetsample