Following question was asked in first round of coding interview.
A 2D grid represent height of land. Find out max height of water to travel from S to E in 2d grid. You can travel up, down, bottom and left direction. You can't jump to a cell if it is submerged with water.
S 3 5 1 5
4 5 1 4 6
3 4 5 6 5
4 6 7 8 EI came up with following approach and wote the code.
Edit: I found exactly similar problem in leetcode. Binary search soln I proposed did work with little modification.
https://leetcode.com/problems/path-with-maximum-minimum-value/
Later I was reading network flow algorithm and realized that this can also be solved applying Ford Fulkerson Edmond Karp algorithm (there is alternate algo as well to use dfs with binary search)
S is sourceE is target i.e. sinkflow as final answerThoughts?