Level: Unknown Level
Round: Phone Screen · Type: Coding · Difficulty: 7/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: Graphs, Dijkstra's Algorithm, Shortest Path, Data Structures, Algorithms
Location: Mountain View, CA
Interview date: 2025-12-31
Question: I was asked to solve a graph problem similar to LeetCode 778, involving finding a path from start to finish in a grid where the cost is the maximum value encountered along the path. I solved it using a modified Dijkstra's algorithm.
The coding question I got was:
Given a grid representing a state map, find the path from the start to the end where the path cost is not the sum of the paths, but the "maximum/worst value encountered on the path" (similar to water level rising; you can only move if the water level >= the height of the cell).
My approach was to directly use a variant of Dijkstra's algorithm:
dist[x] represents the "minimum possible maximum" to reach this point.new = max(dist[cur], height[nxt])
Use a min-heap to run to the end. The complexity is approximately O(n^2 log n) (depending on the grid size). The interviewer was receptive to this.
I also mentioned that I could use binary search for the water level + BFS/DFS to determine connectivity, but Dijkstra's algorithm is cleaner.
The scenario is a general graph: given edge weights (directed/undirected based on the problem), find the shortest time to transmit a signal from a source to all points, output the maximum shortest path (or return -1 if some points are unreachable).
This is a standard Dijkstra's algorithm:
dist to INF, source = 0.dist from the heap and relax the edges.dist; if so, return -1; otherwise, return max(dist).The interviewer asked why the cost is not a normal sum and why Dijkstra's algorithm can still be used (the key is that it "satisfies the optimal substructure + each time the minimum dist point is determined, it will not be updated to be smaller"). They also asked about corner cases, such as the start point = end point, unreachable nodes, and how to handle duplicate entries in the heap (using visited or if curDist!=dist[u] continue).
My approach:
Key insights:
LeetCode similar: LeetCode 778, LeetCode 743