← Airbnb Interview Insights

Airbnb·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Airbnb software engineering interview with a grid-based BFS problem. Pretty standard multi-source BFS setup but they threw in a follow-up about 8-directional spread that caught me off guard mid-explanation.

Questions Asked (2)

Q1

Given an m x n grid where cells are either empty (0), healthy (1), or infected (2), find the minimum number of minutes until all healthy cells are infected via 4-directional spread. Return -1 if some healthy cells can never be reached.

Algorithms & Data Structures
Author's notes

Multi-source BFS, start by seeding all the infected cells into the queue at once.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the spread as a multi-source BFS starting from all initially infected cells simultaneously. Process the grid level by level, incrementing the minute count each level, and after BFS check if any healthy cells remain uninfected. If so, return -1; otherwise return the total minutes elapsed.

Pro tip: Explicitly discuss edge cases like an empty grid, no healthy cells, or no infected cells, and mention that you can optimize space by modifying the grid in-place or using a queue of coordinates.

1. Understand the problem and constraints

Clarify that infection spreads in 4 directions each minute, and we need the minimum time until all healthy cells are infected or determine impossibility. Confirm grid dimensions and cell values.

2. Initialize BFS queue and count healthy cells

Scan the grid to enqueue all initially infected cells (value 2) and count the number of healthy cells (value 1). If there are no healthy cells, return 0 immediately.

3. Perform multi-source BFS level by level

While the queue is not empty, process all nodes at the current level (representing one minute), infecting adjacent healthy cells, marking them as infected, decrementing the healthy count, and enqueueing them for the next level. Increment the minute counter after each level.

4. Check for remaining healthy cells

After BFS completes, if the healthy count is greater than 0, return -1 because some cells are unreachable. Otherwise, return the total minutes elapsed (which is the number of levels processed minus one, or the minute counter after the last infection).

5. Analyze complexity and edge cases

State that time complexity is O(m*n) since each cell is processed at most once, and space complexity is O(m*n) for the queue in the worst case. Mention edge cases like all cells infected initially, no infected cells, or disconnected components.

Key Points to Mention

  • Multi-source BFS to simulate simultaneous spread from all infected cells.
  • Tracking the number of healthy cells to quickly determine if all are infected.
  • Level-order traversal to count minutes accurately.
  • In-place modification of the grid to mark infected cells, avoiding extra space.
  • Handling edge cases: no healthy cells (return 0), no infected cells (return -1 if healthy exist), unreachable healthy cells (return -1).
  • Time and space complexity analysis: O(m*n) time and O(m*n) space.

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

Q2

Extend your solution so that infection spreads in all 8 directions (including diagonals). What changes, and what is the new answer for the same example input?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

They asked this verbally while I was still cleaning up the 4-directional code.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that the only change is expanding the neighbor offsets from 4 to 8 directions, which affects the BFS/DFS traversal. Then, re-run the algorithm on the same example input, showing the step-by-step spread and the final infected grid or time.

Pro tip: Mention that while the code change is trivial, the time complexity remains O(m*n) but the constant factor increases; also note that diagonal spread can cause faster infection, so the answer may differ significantly.

1. Clarify the change

State that the infection now spreads to all 8 neighboring cells (horizontal, vertical, and diagonal) instead of 4.

2. Adjust the algorithm

Modify the direction arrays to include the four diagonal offsets: (-1,-1), (-1,1), (1,-1), (1,1).

3. Re-run on example

Apply the updated BFS/DFS to the same example input, tracking the infection spread step by step.

4. Compute new answer

Determine the new final state or time to full infection, and compare with the original 4-direction result.

5. Discuss implications

Explain any changes in complexity, edge cases (e.g., diagonal blocking), and potential optimizations.

Key Points to Mention

  • Direction arrays: from 4 to 8 offsets
  • BFS/DFS traversal modification
  • Time complexity remains O(m*n) but with larger constant
  • Diagonal spread can bypass obstacles, leading to faster infection
  • Example input re-evaluation: show grid states or infection time
  • Edge cases: boundaries, already infected cells, unreachable cells

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