The Design Graph With Shortest Path Calculator interview question involves building a class that manages a directed, weighted graph. You need to support adding new edges dynamically and querying the shortest path between any two nodes. This Design Graph With Shortest Path coding problem is a test of pathfinding algorithm implementation and system efficiency under mixed read/write loads.
Samsung and Nike ask this to evaluate your mastery of Graph interview patterns, specifically Dijkstra’s Algorithm or Floyd-Warshall. It tests whether you can choose the right algorithm based on how often edges are added versus how often shortest paths are queried. It evaluates your knowledge of Heap (Priority Queue) interview patterns for optimization.
addEdge(0, 1, 5), addEdge(1, 2, 10), addEdge(0, 2, 20).shortestPath(0, 2):
addEdge(0, 2, 2):shortestPath(0, 2): Dijkstra now returns 2.Always discuss the tradeoffs! If the interviewer says edges are added rarely, suggest Floyd-Warshall for queries. If edges are added often, Dijkstra is much better. Being able to analyze these scenarios shows senior-level architectural thinking.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Shortest Path with K Hops | Hard | Solve | |
| Minimum Weighted Subgraph With the Required Paths | Hard | Solve | |
| Modify Graph Edge Weights | Hard | Solve | |
| Reachable Nodes In Subdivided Graph | Hard | Solve | |
| Minimum Cost Path with Edge Reversals | Medium | Solve |