← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediateRejected
Aug 2026

Summary

Interviewed at Google for a software engineer role. Behavioral went well apparently, but the coding round is what got me. They passed, and I'm looking at a 6-month wait before I can try again.

Questions Asked (2)

Q1

Implement a graph traversal using BFS to solve a search problem.

Algorithms & Data Structures
Author's notes

Nailed this part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining the problem in graph terms — identify nodes, edges, and what 'finding a solution' means — before writing any code. Implement BFS iteratively using a queue and a visited set, explaining your choices as you go. Walk through a concrete example to validate correctness, then discuss time and space complexity.

Pro tip: Google interviewers value candidates who proactively discuss *why* BFS is the right choice over DFS for this problem (e.g., shortest path, level-order guarantees) — explicitly stating this trade-off signals strong algorithmic intuition rather than just pattern-matching to a template.

1. Clarify & Model the Problem

Ask clarifying questions to understand the graph structure (directed/undirected, weighted/unweighted, cyclic) and the search goal (shortest path, reachability, etc.). Explicitly state why BFS is appropriate — typically because it guarantees the shortest path in an unweighted graph.

2. Define Data Structures

Choose a queue (collections.deque in Python) for the BFS frontier and a visited set to prevent revisiting nodes. If path reconstruction is needed, also maintain a parent/predecessor map.

3. Implement BFS Iteratively

Initialize the queue with the source node(s) and mark them visited, then loop: dequeue a node, check if it's the goal, and enqueue all unvisited neighbors while marking them visited. Narrate each decision aloud to demonstrate clear thinking.

4. Trace Through an Example

Walk through a small, concrete example (draw the graph if possible) to verify your implementation handles edge cases like disconnected graphs, the source equaling the target, or no path existing.

5. Analyze Complexity & Discuss Trade-offs

State time complexity O(V + E) and space complexity O(V) for the queue and visited set. Mention trade-offs versus DFS (stack vs. queue, memory usage for wide graphs) and potential optimizations like bidirectional BFS for large graphs.

Key Points to Mention

  • Use a deque for O(1) popleft operations instead of a list to avoid O(n) shifts
  • Always mark nodes as visited when enqueuing (not when dequeuing) to prevent duplicate entries in the queue
  • BFS guarantees the shortest path in terms of edge count for unweighted graphs — state this explicitly
  • Handle edge cases: empty graph, source node not in graph, source equals target, disconnected components
  • For path reconstruction, maintain a parent dictionary and backtrack from the target to the source
  • Mention bidirectional BFS as an advanced optimization that reduces search space from O(b^d) to O(b^(d/2))

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

Q2

Follow-up: re-implement the same BFS solution using recursion instead of an iterative approach.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where things fell apart.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Acknowledge that BFS is inherently iterative due to its level-order traversal, but show how recursion can simulate it by passing depth or using a queue-like structure. Implement a recursive function that processes nodes level by level, using a helper that tracks the current level and a list of nodes at that level. Discuss the trade-offs: recursion adds call stack overhead and may hit depth limits, but can be more elegant for certain tree problems.

Pro tip: Mention that while recursive BFS is possible, it's often less efficient and can cause stack overflow for deep graphs; interviewers appreciate when you recognize that iterative BFS is usually preferred and explain why.

1. Clarify the problem and constraints

Confirm whether the graph is a tree or general graph, and if recursion depth is a concern. Ask if they expect a true BFS order or just a level-order traversal.

2. Outline the recursive strategy

Explain that you'll use a helper function that takes a list of nodes at the current level and processes them, then recurses on the next level's nodes. This simulates BFS by processing level by level.

3. Implement the recursive function

Write a function that takes the current level's nodes, processes them, collects their children, and if children exist, recursively calls itself with the children list. Use a visited set to avoid cycles in graphs.

4. Analyze time and space complexity

State that time complexity remains O(V+E) as each node and edge is processed once, but space complexity includes recursion stack depth O(D) where D is the maximum depth, plus the level lists.

5. Discuss trade-offs and alternatives

Compare with iterative BFS: recursion may be simpler for trees but risks stack overflow for deep graphs; iterative BFS uses explicit queue and is safer for large graphs. Mention that for very deep graphs, iterative is preferred.

Key Points to Mention

  • BFS is naturally iterative; recursion can simulate it by processing level by level.
  • Use a helper function that takes a list of nodes at the current level and recurses on the next level.
  • Maintain a visited set to handle cycles in general graphs.
  • Time complexity remains O(V+E), but space complexity includes O(D) recursion stack depth.
  • Recursive BFS may cause stack overflow for deep graphs; iterative BFS is generally safer.
  • For trees, recursive level-order traversal can be elegant, but for graphs, iterative BFS is standard.

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