← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Amazon SWE interview with a graph shortest path problem. Pretty standard stuff but I fumbled a bit on the details.

Questions Asked (1)

Q1

Find the shortest path between two nodes in a graph.

Algorithms & Data Structures
Author's notes

Went with BFS for unweighted, mentioned Dijkstra for weighted.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the graph type (directed/undirected, weighted/unweighted) and the definition of 'shortest' (fewest edges or minimum weight). Then select the appropriate algorithm: BFS for unweighted graphs, Dijkstra for non-negative weights, or Bellman-Ford for negative weights, and explain the reasoning behind your choice.

Pro tip: At Amazon, interviewers value candidates who proactively discuss trade-offs and edge cases, so after presenting your solution, mention how you would handle large-scale graphs or negative cycles, and ask if the graph is static or dynamic.

1. Clarify the problem

Ask questions to determine if the graph is directed or undirected, weighted or unweighted, and whether edge weights can be negative. Also confirm if the graph is connected and if there are multiple shortest paths.

2. Choose the right algorithm

Based on the clarifications, select BFS for unweighted graphs, Dijkstra for non-negative weighted graphs, or Bellman-Ford for graphs with negative weights. Explain why the chosen algorithm is optimal for the given constraints.

3. Outline the algorithm

Describe the step-by-step process: initialize distances, use a queue (BFS) or priority queue (Dijkstra), relax edges, and track predecessors to reconstruct the path. Mention time and space complexity.

4. Handle edge cases and optimizations

Discuss edge cases such as disconnected graphs, negative cycles, or when the source and target are the same. Suggest optimizations like early termination in Dijkstra when the target is reached.

5. Reconstruct and verify

Explain how to reconstruct the shortest path using parent pointers and verify the solution with a small example. Mention that you would test with various graph types.

Key Points to Mention

  • BFS for unweighted graphs, Dijkstra for non-negative weighted graphs, Bellman-Ford for negative weights
  • Time and space complexity: O(V+E) for BFS, O((V+E) log V) for Dijkstra with a binary heap, O(VE) for Bellman-Ford
  • Use of priority queue in Dijkstra and relaxation process
  • Handling of disconnected graphs and unreachable nodes
  • Path reconstruction using parent pointers
  • Edge cases: negative cycles, source equals target, large graphs

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.