Rising Water Wait Problem

Rising Water Wait Problem — ExecCode Hard DSA Practice

Solve the Rising Water Wait problem on ExecCode. Free online hard DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.

Problem description

A grid floods: at time t every cell with height <= t is underwater and walkable. You start at (0,0) and want (n-1,n-1), moving 4-directionally. You can wait. The answer is the minimum t such that a path exists using only cells with height <= t — equivalent to minimax path via a min-heap. Return the least possible time (the max height on the chosen path, minimized). You are given: grid — n×n distinct heights in typical OA; duplicates allowed here Return integer time. The start cell's height is already a lower bound on the answer.

Examples

Input {'grid': [[0, 2], [1, 3]]}; Output 3. Input {'grid': [[3]]}; Output 3. Input {'grid': [[1, 2, 3], [8, 9, 4], [7, 6, 5]]}; Output 5

Constraints

You may wait; moving onto a taller cell requires waiting until t equals that height n >= 1

Practice Rising Water Wait free on ExecCode. Browse DSA problems, topic map, and placement guides.