← Coupang Interview Insights

Coupang·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Coupang software engineer interview with a graph problem that looks straightforward but has a few layers to it. Nothing too wild, but the BFS/multi-source setup tripped me up a bit.

Questions Asked (1)

Q1

Given a binary grid with exactly two 4-directionally connected islands, find the minimum number of water cells you need to flip to land in order to connect the two islands.

Algorithms & Data Structures
Author's notes

My first instinct was just BFS from one island toward the other, which is mostly right, but I fumbled the setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path between two sets of cells: first identify the two islands via BFS/DFS, then run a multi-source BFS from one island to find the minimum distance to the other, where distance is the number of water cells crossed. Alternatively, compute the minimum Manhattan distance between any land cell of island A and any land cell of island B, but be careful because the shortest path may not be a straight line due to obstacles.

Pro tip: Clarify whether flipping a water cell to land can connect diagonally or only 4-directionally; the problem states 4-directionally connected islands, so the connection must also be 4-directionally. Also, mention that the answer is at least 1 because the islands are separate, and you can use 0-1 BFS or multi-source BFS to handle the cost of flipping water cells efficiently.

1. Identify the two islands

Use BFS or DFS to label each land cell with its island ID (1 or 2). This separates the grid into two sets of coordinates.

2. Choose a search strategy

Decide between multi-source BFS from one island to the other, or computing minimum Manhattan distance between all pairs of land cells. Multi-source BFS is more robust for obstacles.

3. Run multi-source BFS

Initialize a queue with all cells of island 1, and BFS layer by layer. Each step into a water cell increments the distance by 1. Stop when you reach any cell of island 2.

4. Return the minimum flips

The BFS distance when first hitting island 2 is the minimum number of water cells to flip. If using Manhattan distance, compute min over all pairs of (|r1-r2| + |c1-c2| - 1) but verify with BFS.

5. Analyze complexity and edge cases

Time O(R*C), space O(R*C). Discuss edge cases: islands adjacent diagonally (answer 1), large grid, and ensuring BFS doesn't revisit cells.

Key Points to Mention

  • Use BFS/DFS to identify the two islands and their cells.
  • Multi-source BFS from one island to find shortest path to the other.
  • Distance metric: number of water cells flipped (each water cell adds 1).
  • Time and space complexity: O(R*C) for grid dimensions R and C.
  • Edge case: islands already connected? Problem says exactly two, so not connected.
  • Alternative: Manhattan distance between closest land cells, but may overestimate if obstacles block.

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