← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE interview with a graph theory question that went deeper than I expected. No code required, just reasoning out loud, which sounds easier than it is when someone's watching you think.

Questions Asked (3)

Q1

For an unweighted graph, walk through how you'd find the shortest path between two nodes without writing any code. Explain the algorithm step by step, analyze its time and space complexity, and justify why it actually works.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The 'no code' part tripped me up more than the actual algorithm.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that BFS is the optimal algorithm for unweighted graphs, then walk through the algorithm step-by-step using a concrete example. Explain how BFS explores level by level, ensuring the first time you reach the target, you've found the shortest path. Finally, analyze time and space complexity and justify correctness via the level-order property.

Pro tip: Mention that BFS finds the shortest path in terms of number of edges, and if the graph is disconnected, you should check reachability first. Also, note that for very large graphs, bidirectional BFS can be more efficient.

1. Choose BFS and justify

Explain that BFS is the right choice because it explores nodes in order of distance from the source, guaranteeing the shortest path in unweighted graphs.

2. Initialize data structures

Use a queue to manage the frontier, a visited set to avoid cycles, and a parent map to reconstruct the path.

3. Traverse level by level

Dequeue a node, enqueue its unvisited neighbors, mark them visited, and record their parent. Stop when the target is dequeued or enqueued.

4. Reconstruct the path

If the target is found, backtrack from the target using the parent map to build the shortest path from source to target.

5. Analyze complexity and correctness

State that time complexity is O(V+E) and space is O(V). Justify correctness by the fact that BFS visits nodes in non-decreasing order of distance from the source.

Key Points to Mention

  • BFS explores nodes in layers, ensuring the first time the target is reached, it's via the shortest path.
  • Use a queue for FIFO order, a visited set to prevent revisiting, and a parent map for path reconstruction.
  • Time complexity: O(V + E) for adjacency list representation; space complexity: O(V) for queue, visited, and parent structures.
  • Correctness proof: By induction, all nodes at distance d are visited before any at distance d+1, so the target is first reached at its minimum distance.
  • Edge cases: source equals target, disconnected graph (no path), and handling large graphs with bidirectional BFS.
  • Mention that for weighted graphs, BFS doesn't work; Dijkstra's algorithm is needed.

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

Q2

Compare BFS and DFS for shortest path finding. When would you use each, and what are the trade-offs in terms of correctness, time/space complexity, and memory usage?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I think I actually did okay.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining BFS and DFS and their fundamental properties, then compare them specifically for shortest path finding in unweighted graphs. Structure your answer around correctness, time/space complexity, and memory usage, and conclude with practical scenarios for when to use each.

Pro tip: Mention that BFS guarantees the shortest path in unweighted graphs, but for weighted graphs, Dijkstra's algorithm (a BFS variant) is needed; this shows depth beyond the basics. Also, note that DFS can be adapted for shortest path in trees or DAGs with topological sort, but it's not general.

1. Define BFS and DFS

Briefly explain that BFS explores level by level using a queue, while DFS explores as deep as possible using a stack (or recursion).

2. Correctness for shortest path

State that BFS is correct for finding shortest paths in unweighted graphs because it visits nodes in order of distance from the source. DFS does not guarantee shortest paths in general graphs.

3. Time and space complexity

Compare: Both have O(V+E) time for graph traversal. BFS space is O(V) for queue and visited set, which can be large for wide graphs. DFS space is O(h) for recursion stack, where h is the maximum depth, which can be O(V) in worst case.

4. Memory usage and practical trade-offs

Discuss that BFS may use more memory for wide graphs due to storing all nodes at a level, while DFS uses less memory for deep graphs but can be risky due to stack overflow. Mention that BFS is preferred for shortest path in unweighted graphs, while DFS is useful for topological sorting, cycle detection, and path existence.

5. When to use each

Summarize: Use BFS for shortest path in unweighted graphs, or when the target is likely close to the source. Use DFS for memory-constrained scenarios on deep graphs, or when you need to explore all paths (e.g., backtracking).

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs; DFS does not.
  • Time complexity: both O(V+E) for traversal.
  • Space complexity: BFS O(V) for queue; DFS O(h) for stack, where h is max depth.
  • BFS memory can be high for wide graphs; DFS memory can be high for deep graphs (recursion stack).
  • For weighted graphs, BFS is insufficient; use Dijkstra's algorithm (which is like BFS with a priority queue).
  • DFS can be used for shortest path in trees or DAGs with topological sort, but not general graphs.

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

Q3

How does your approach change when the graph has weights on its edges?

Algorithms & Data Structures
Author's notes

Pivoted to Dijkstra's pretty quickly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging that edge weights fundamentally change the problem's objective from minimizing hops to minimizing total cost, which often invalidates BFS. Then systematically discuss how to adapt algorithms like Dijkstra for non-negative weights, Bellman-Ford for negative weights, and specialized approaches for DAGs or dense graphs, while highlighting trade-offs in time complexity and data structures.

Pro tip: Always clarify the weight properties (non-negative, negative, zero) and whether the graph is directed or a DAG before diving into algorithm selection; this shows you think about constraints first and avoids suggesting an invalid algorithm like Dijkstra with negative edges.

1. Clarify weight properties and graph type

Ask about edge weight ranges (non-negative, negative, zero), whether the graph is directed or undirected, and if it's a DAG. This determines which algorithms are applicable.

2. Re-evaluate the problem objective

Explain that with weights, the goal shifts from minimizing number of edges to minimizing total weight, so BFS is no longer optimal for shortest paths unless all weights are equal.

3. Select appropriate algorithm

For non-negative weights, use Dijkstra with a priority queue (O(E log V)). For negative weights, use Bellman-Ford (O(VE)) or SPFA. For DAGs, use topological sort with relaxation (O(V+E)).

4. Discuss data structures and optimizations

Mention using a min-heap for Dijkstra, and consider alternatives like Fibonacci heaps for theoretical improvements. For dense graphs, adjacency matrix with O(V^2) Dijkstra may be better.

5. Analyze trade-offs and edge cases

Compare time/space complexities, discuss handling negative cycles (Bellman-Ford detects them), and note that for unweighted graphs, BFS remains optimal.

Key Points to Mention

  • BFS is insufficient for weighted graphs because it assumes uniform edge cost.
  • Dijkstra's algorithm requires non-negative weights and uses a priority queue for efficiency.
  • Bellman-Ford handles negative weights and can detect negative cycles, but is slower.
  • For DAGs, topological sort allows linear-time shortest path computation even with negative weights.
  • A* search can be used if a heuristic is available, common in pathfinding.
  • Time complexity trade-offs: Dijkstra O(E log V) vs Bellman-Ford O(VE) vs DAG O(V+E).

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