Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon/Microsoft-style OA

Problem: A grid of R × C = 10³ × 10³ heights; find the minimum possible 'maximum step height' along any path from top-left to bottom-right. Which approaches are correct and efficient?

  1. A. Dijkstra where a path's cost is its maximum edge (minimax), or binary search on the limit with BFS, or Kruskal-style union-find – each about O(RC log RC)
  2. B. Plain BFS for the fewest steps
  3. C. DP moving only right/down
  4. D. DFS returning the first path found

Correct answer: A. Dijkstra where a path's cost is its maximum edge (minimax), or binary search on the limit with BFS, or Kruskal-style union-find – each about O(RC log RC)

The bottleneck path minimises the largest edge; Dijkstra works with max instead of sum, binary search over the threshold with a BFS feasibility check also works, and so does adding edges in increasing order until the corners connect. DP restricted to right/down misses paths that go up or left.

More Coding Interview Problems questions

Exams that ask this topic