← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Amazon SWE coding round, one question the whole time, grid-based flow problem that's basically a twist on a classic LC problem. Not the hardest thing I've done but I fumbled the setup more than I'd like to admit.

Questions Asked (1)

Q1

Given an m x n grid where each cell has a height value, water flows from a cell to any adjacent cell (4-directional) with height less than or equal to the current cell. Water is dropped on a specific set of starting points and flows until it exits the grid. Return all cells that end up wet.

Algorithms & Data Structures
Author's notes

I recognized it was related to the Pacific Atlantic problem pretty fast, which helped.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a directed graph where edges point from higher/equal cells to lower/equal cells, then run a multi-source BFS/DFS from all starting points to find all reachable cells. Alternatively, reverse the flow direction and propagate from boundary cells inward, but since starting points are given, forward propagation is more direct. Use a queue for BFS to efficiently explore all reachable cells.

Pro tip: Clarify with the interviewer whether water can flow to equal-height cells (yes, per problem) and whether starting points are guaranteed to be inside the grid. Also, consider using a visited set to avoid cycles and ensure O(m*n) time complexity.

1. Understand the problem and constraints

Confirm the flow rule (to adjacent cells with height <= current), the grid dimensions, and that starting points are given. Ask about edge cases like multiple starting points, equal heights, and whether water can flow out of the grid.

2. Choose the right algorithm

Recognize this as a graph traversal problem. Since we need all cells reachable from multiple sources, a multi-source BFS or DFS is appropriate. BFS is often preferred for shortest path but here any traversal works; BFS with a queue is straightforward.

3. Implement the traversal

Initialize a queue with all starting points and a visited set. While the queue is not empty, pop a cell, mark it as wet, and for each of its 4 neighbors, if the neighbor's height <= current cell's height and not visited, add it to the queue.

4. Collect and return results

After traversal, the visited set contains all wet cells. Return them as a list of coordinates or a boolean grid, depending on the required output format.

5. Analyze complexity and test

Time complexity is O(m*n) since each cell is visited at most once. Space complexity is O(m*n) for the queue and visited set. Test with edge cases: single cell, all equal heights, starting points on boundaries, and disconnected regions.

Key Points to Mention

  • Graph traversal (BFS/DFS) with multiple sources
  • Directional edges based on height comparison (<=)
  • Visited set to avoid cycles and redundant work
  • Time and space complexity: O(m*n)
  • Handling of equal heights and boundary conditions
  • Potential alternative: reverse flow from boundaries if starting points were not given

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