← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE interview that was basically a maze problem session. The base case was straightforward but the follow-up with the block conversion rule is where things got interesting and I think I almost went down the wrong path before catching myself.

Questions Asked (2)

Q1

Given an m x n grid where each cell is either free or blocked, find whether a path exists from the top-left to the bottom-right and return the length of the shortest such path.

Algorithms & Data Structures
Author's notes

Standard BFS with a visited set, nothing too tricky.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as an unweighted graph and use BFS from the top-left cell to find the shortest path to the bottom-right, tracking distance as you go. Clarify edge cases (start/end blocked, empty grid) and state time/space complexity before coding.

Pro tip: Mention that BFS guarantees the shortest path in an unweighted grid, and note that you can optimize space by marking visited cells in-place or using a direction array—this shows attention to practical constraints.

1. Clarify problem and edge cases

Confirm grid dimensions, movement allowed (4-directional), and handle cases like start/end blocked, 1x1 grid, or no path. State assumptions clearly.

2. Choose BFS and explain why

Explain that BFS explores level by level, guaranteeing the shortest path in an unweighted grid, unlike DFS which may find a longer path first.

3. Outline BFS algorithm

Describe using a queue storing (row, col, distance), a visited set or in-place marking, and checking bounds and blocked cells before enqueuing neighbors.

4. Analyze complexity

State that time complexity is O(m*n) since each cell is visited at most once, and space complexity is O(m*n) for the queue and visited structure in the worst case.

5. Discuss optimizations and variations

Mention bidirectional BFS for potential speedup, or using a distance matrix if the grid must remain unchanged. Briefly note how to adapt for 8-directional movement.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue and track distance (or level) during traversal
  • Mark visited cells to avoid cycles and redundant work
  • Handle edge cases: start/end blocked, no path, 1x1 grid
  • Time and space complexity: O(m*n)
  • Potential optimization: bidirectional BFS or in-place marking

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

Q2

Follow-up: you can convert at most one blocked cell into a free cell during traversal. Find the shortest path under this new rule.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to iterate over every blocked cell, flip it, run BFS each time, and take the minimum.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path on an expanded state graph where each state includes the number of blocked cells converted so far (0 or 1). Run BFS from the start, allowing transitions through free cells with the same conversion count and through blocked cells only if the count is 0 (incrementing it to 1). The first time you reach the destination with either conversion count gives the shortest path length.

Pro tip: Mention that the expanded graph has at most 2*N*M states, so BFS remains O(N*M) and is optimal for unweighted grids; this shows you understand both correctness and complexity trade-offs.

1. Define the state space

Represent each state as (row, col, used_conversion) where used_conversion is 0 or 1. This captures whether the single allowed conversion has been used.

2. Set up BFS transitions

From a state, move to adjacent free cells with the same used_conversion; move to adjacent blocked cells only if used_conversion is 0, transitioning to used_conversion=1.

3. Initialize and run BFS

Start BFS from (start_row, start_col, 0) with distance 0. Use a queue and a visited array of size N x M x 2 to avoid revisiting states.

4. Terminate and return

When you dequeue the destination cell with either used_conversion value, return the current distance as the shortest path length. If BFS exhausts without reaching it, return -1.

5. Analyze complexity

State the time and space complexity: O(N*M) since each cell is visited at most twice (once per conversion count), and the queue/visited structures are proportional to 2*N*M.

Key Points to Mention

  • State-space expansion with an extra dimension for conversion usage
  • BFS guarantees shortest path in unweighted graphs
  • Visited array must track (row, col, used_conversion) to avoid cycles and redundant work
  • Only allow conversion when used_conversion == 0, and mark it as used afterward
  • Time and space complexity: O(N*M) with a constant factor of 2
  • Edge cases: start or end is blocked, no path exists, grid boundaries

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