← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Amazon SWE interview with two coding problems. The second one was a custom graph/BFS hybrid that felt way harder than anything I'd seen on LeetCode.

Questions Asked (2)

Q1

Rotting Oranges (LeetCode 994): given a grid of fresh and rotten oranges, find the minimum time for all oranges to rot via BFS spread, or return -1 if impossible.

Algorithms & Data Structures
Author's notes

Fairly standard multi-source BFS.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a graph where each cell is a node, and use multi-source BFS starting from all initially rotten oranges simultaneously. Track the time level by level, counting minutes until no fresh oranges remain, and return the total time or -1 if any fresh orange is unreachable.

Pro tip: Explicitly discuss time and space complexity (O(m*n) time, O(m*n) space) and mention edge cases like an empty grid, no fresh oranges, or disconnected fresh oranges. This shows you think about efficiency and robustness, which Amazon values.

1. Clarify and Define the Problem

Restate the problem in your own words, confirm the rules (rot spreads to 4-directionally adjacent fresh oranges each minute), and ask clarifying questions about edge cases (e.g., empty grid, no fresh oranges, multiple rotten sources).

2. Choose the Algorithm

Explain that this is a shortest-path problem on an unweighted grid, so BFS is ideal. Emphasize that because rot spreads from multiple sources simultaneously, a multi-source BFS is needed.

3. Outline the BFS Implementation

Describe initializing a queue with all rotten oranges, tracking fresh count, and processing level by level. For each minute, process all nodes at the current level, rot adjacent fresh oranges, and increment time.

4. Handle Edge Cases and Termination

Explain how to detect if all oranges rot (fresh count reaches zero) and return the time, or if some remain fresh after BFS, return -1. Mention handling grids with no fresh oranges (return 0).

5. Analyze Complexity and Optimizations

State the time complexity O(m*n) since each cell is visited once, and space complexity O(m*n) for the queue. Discuss potential optimizations like in-place modification of the grid to avoid extra space.

Key Points to Mention

  • Multi-source BFS: initialize queue with all rotten oranges to simulate simultaneous spread.
  • Level-by-level processing to track elapsed time (minutes).
  • Tracking fresh orange count to determine if all rot and to return -1 if not.
  • Time and space complexity: O(m*n) time, O(m*n) space.
  • Edge cases: empty grid, no fresh oranges, no rotten oranges, disconnected fresh oranges.
  • In-place modification of the grid to mark rotten oranges and avoid using a separate visited set.

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

Q2

You're given start and end coordinates on a grid, a maximum total walking budget k (measured in Manhattan distance), and a list of bus stations connected as a bidirectional graph where riding the bus is free. Can you get from start to end if walking between any two points costs Manhattan distance and your total walking must stay within k?

Algorithms & Data StructuresSystem Design
Author's notes

This one took me a while to even parse.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path on a graph where nodes are start, end, and all bus stations, with edge weights equal to Manhattan distances for walking and 0 for bus edges. Run Dijkstra's algorithm to find the minimum walking distance from start to end, then check if it is ≤ k.

Pro tip: Mention that you can optimize by only considering bus stations that are within k walking distance from start or end, and that using a priority queue ensures efficiency even with many stations.

1. Model the graph

Create nodes for start, end, and all bus stations. Add walking edges between every pair of nodes with weight equal to Manhattan distance, and add bus edges with weight 0 for each connection in the given bus graph.

2. Run shortest path

Use Dijkstra's algorithm to compute the minimum total walking distance from start to end, treating bus rides as free.

3. Check budget

Compare the computed minimum walking distance to k. If it is ≤ k, return true; otherwise, return false.

4. Optimize if needed

If the number of stations is large, consider pruning stations that are farther than k from both start and end, or use A* with a heuristic based on Manhattan distance.

Key Points to Mention

  • Manhattan distance as the walking cost metric
  • Bus rides are free (0 cost edges)
  • Graph modeling with start, end, and bus stations as nodes
  • Dijkstra's algorithm for shortest path with non-negative weights
  • Time complexity: O((N+M) log N) where N is number of nodes and M is number of edges
  • Space complexity: O(N+M) for the graph representation

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