← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Amazon SWE technical phone screen, one question, pure algorithms. They wanted the full treatment: correctness argument, complexity, edge cases, pseudocode. Pretty standard BFS grid problem but they pushed hard on the details.

Questions Asked (1)

Q1

Given an m x n grid where -1 marks an obstacle and all other cells are passable, find the shortest path from the top-left to the bottom-right corner using only four-directional moves. Return -1 if no path exists. Walk through your algorithm, argue its correctness, analyze time and space complexity, handle edge cases like a blocked start or goal or a single-cell grid, and write pseudocode.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

BFS is the obvious call here and I got there fast, but then they kept pulling on threads.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use BFS from the start cell, treating each cell as a node and four-directional moves as edges, because BFS guarantees the shortest path in an unweighted grid. Before searching, check edge cases like blocked start/goal or single-cell grid, and during BFS track visited cells to avoid cycles. If the goal is reached, return the distance; otherwise return -1.

Pro tip: Explicitly state that BFS is optimal for unweighted shortest path and contrast it with DFS, which does not guarantee shortest paths. Also, mention that you can optimize space by using a distance array or modifying the grid in-place if allowed.

1. Clarify problem and edge cases

Restate the problem: find shortest path in a grid with obstacles using 4-directional moves. Identify edge cases: start or goal blocked, single-cell grid, empty grid, and no path.

2. Choose algorithm and data structures

Select BFS because it finds shortest path in unweighted graphs. Use a queue for BFS and a 2D array or set for visited cells to avoid revisiting.

3. Walk through BFS algorithm

Initialize queue with start cell and distance 0. While queue not empty, dequeue cell, check if goal, else enqueue all valid unvisited neighbors with distance+1. Mark visited when enqueuing.

4. Argue correctness and complexity

Explain BFS explores cells in increasing distance order, so first time goal is reached is shortest. Time complexity O(m*n) since each cell visited once; space O(m*n) for queue and visited.

5. Write pseudocode and test edge cases

Provide clear pseudocode covering initialization, BFS loop, and return -1. Verbally test with blocked start/goal, single cell, and no path scenarios.

Key Points to Mention

  • BFS guarantees shortest path in unweighted grids, unlike DFS.
  • Time complexity O(m*n) and space complexity O(m*n) due to queue and visited set.
  • Edge cases: start or goal is -1, single-cell grid (return 0 if passable, -1 if blocked), no path exists.
  • Use a visited set or modify grid in-place to avoid revisiting cells.
  • Four-directional moves: up, down, left, right; check boundaries.
  • Return -1 if queue exhausts without reaching goal.

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