← Meta Interview Insights

Meta·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Meta ML engineer coding round, all grid traversal stuff. Four follow-ups stacked on top of each other, each one building on the last. Felt like a gauntlet more than a single question.

Questions Asked (4)

Q1

Given a 2D grid with walls, a start cell, and a goal cell, can you determine whether the goal is reachable from the start?

Algorithms & Data Structures
Author's notes

Standard BFS reachability check.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (grid size, movement allowed, wall representation) and then propose a graph traversal algorithm such as BFS or DFS to determine reachability. Explain the algorithm step-by-step, analyze time and space complexity, and discuss potential optimizations or edge cases.

Pro tip: Mention that BFS is generally preferred for reachability because it finds the shortest path if one exists, and it can be more memory-efficient than DFS in wide grids. Also, highlight that you can stop early once the goal is found.

1. Clarify the problem

Ask about grid dimensions, movement directions (4-way or 8-way), wall representation, and whether the start and goal are guaranteed to be valid cells. Confirm if diagonal moves are allowed and if there are any constraints on memory or time.

2. Choose an algorithm

Select BFS for shortest path and optimal reachability, or DFS for simpler implementation if only reachability matters. Consider A* if heuristic is available and performance is critical.

3. Outline the algorithm

Describe initializing a queue with the start cell, marking visited cells, and iteratively exploring neighbors until the goal is found or the queue is empty. Emphasize handling boundaries and walls.

4. Analyze complexity

State that time complexity is O(R*C) for BFS/DFS, where R and C are grid dimensions, and space complexity is O(R*C) in the worst case due to the queue/stack and visited set.

5. Discuss edge cases and optimizations

Mention edge cases like start equals goal, unreachable goal, or no walls. Suggest optimizations like bidirectional BFS or using a visited matrix to avoid revisiting cells.

Key Points to Mention

  • BFS vs DFS trade-offs: BFS finds shortest path, DFS uses less memory in some cases.
  • Visited set to avoid cycles and redundant work.
  • Time and space complexity: O(R*C) for both BFS and DFS.
  • Handling of grid boundaries and wall cells.
  • Early termination when goal is reached.
  • Potential use of A* if a heuristic is available.

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

Q2

Now find the shortest path length between the start and goal in the same grid.

Algorithms & Data Structures
Author's notes

BFS naturally gives you this if you track depth.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as an unweighted graph and use BFS to find the shortest path length from start to goal. If the grid has weighted cells, use Dijkstra's algorithm instead. Clearly state the assumptions about movement (4-directional vs 8-directional) and obstacles.

Pro tip: Mention that BFS is optimal for unweighted grids and that you can optimize space by using a 2D distance array or in-place marking. Also, discuss how to handle edge cases like start equals goal or no path exists.

1. Clarify the problem

Ask about movement rules (4 or 8 directions), whether cells have weights, and if diagonal moves are allowed. Confirm if the grid contains obstacles and if start/goal are guaranteed to be valid.

2. Choose the algorithm

For unweighted grids, BFS is optimal. For weighted grids, use Dijkstra's algorithm. Mention that A* with Manhattan distance heuristic can be more efficient if the grid is large and obstacles are sparse.

3. Implement BFS

Use a queue to explore level by level, tracking visited cells to avoid cycles. Maintain a distance array or store distance in the queue. Return the distance when the goal is reached.

4. Analyze complexity

Time complexity is O(R*C) for BFS, where R and C are grid dimensions. Space complexity is O(R*C) for the visited set and queue. For Dijkstra, it's O(R*C log(R*C)).

5. Test and handle edge cases

Test with start equal to goal, no path, single row/column, and large grids. Discuss how to reconstruct the path if needed, not just the length.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue and visited set to avoid revisiting cells
  • Time and space complexity: O(R*C) for BFS
  • Handling obstacles and boundary conditions
  • Alternative algorithms: Dijkstra for weighted grids, A* for heuristic search
  • Path reconstruction using parent pointers if required

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

Q3

Reconstruct the actual path taken, not just the length.

Algorithms & Data Structures
Author's notes

This is where I fumbled slightly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the problem is to find the shortest path and reconstruct the sequence of nodes, not just the distance. Choose an algorithm like BFS for unweighted graphs or Dijkstra/A* for weighted graphs, and maintain a predecessor map to backtrack from the target to the source. After computing the shortest distances, reconstruct the path by following predecessors and then reverse it to get the correct order.

Pro tip: Mention that you can reconstruct the path without storing the entire path at each step by using a parent pointer array, which saves memory and is efficient. Also, discuss how to handle multiple shortest paths or tie-breaking if the problem requires a specific one.

1. Clarify the problem

Confirm whether the graph is weighted or unweighted, directed or undirected, and whether we need any shortest path or a specific one. Ask about edge cases like no path existing.

2. Choose the right algorithm

For unweighted graphs, BFS is optimal; for weighted graphs with non-negative weights, use Dijkstra; for negative weights, Bellman-Ford. Mention A* if heuristic is available.

3. Track predecessors

During traversal, maintain a parent array or map that records the previous node for each visited node. This allows reconstructing the path later.

4. Reconstruct the path

Starting from the target node, follow the parent pointers back to the source, collecting nodes. Reverse the collected list to get the path from source to target.

5. Handle edge cases and complexity

If no path exists, return empty or appropriate message. Analyze time and space complexity: O(V+E) for BFS, O(E log V) for Dijkstra, plus O(V) for path reconstruction.

Key Points to Mention

  • BFS for unweighted graphs guarantees shortest path in terms of number of edges.
  • Dijkstra's algorithm for weighted graphs with non-negative weights, using a priority queue.
  • Parent pointer array (or predecessor map) to store the previous node for each visited node.
  • Backtracking from target to source using parent pointers, then reversing the path.
  • Time and space complexity: O(V+E) for BFS, O(E log V) for Dijkstra, plus O(V) for path storage.
  • Handling cases where no path exists or multiple shortest paths exist.

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

Q4

Handle a variant of the grid problem, such as portals between cells, weighted movement costs, multiple goal cells, or finding all shortest paths.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

They went with weighted cells, so BFS is out and you need Dijkstra.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem variant and constraints first, then choose the appropriate shortest-path algorithm (e.g., Dijkstra for weighted costs, BFS for unweighted, multi-source BFS for multiple goals). Discuss trade-offs between algorithms and data structures, and outline how to adapt the solution for portals or all shortest paths.

Pro tip: Always discuss time and space complexity and consider edge cases like negative weights or unreachable goals; showing awareness of these demonstrates maturity and thoroughness.

1. Clarify the problem

Ask questions to understand the exact variant: are there portals, weighted edges, multiple goals, or need for all shortest paths? Confirm constraints like grid size, edge weights, and whether weights are non-negative.

2. Choose the right algorithm

Select the algorithm based on the variant: BFS for unweighted, Dijkstra for non-negative weighted, Bellman-Ford for negative weights, or multi-source BFS for multiple goals. For portals, model them as additional edges or nodes.

3. Design the data structures

Decide on representations: adjacency list or grid with implicit edges, priority queue for Dijkstra, queue for BFS, and distance arrays. For all shortest paths, consider storing predecessors or using BFS/Dijkstra with path tracking.

4. Analyze complexity and trade-offs

Discuss time and space complexity of your approach, and compare with alternatives. Mention how portals or multiple goals affect complexity and how to optimize.

5. Handle edge cases and test

Consider unreachable goals, negative cycles, large grids, and portals creating cycles. Walk through a small example to validate the approach.

Key Points to Mention

  • Dijkstra's algorithm for weighted grids with non-negative weights, using a priority queue.
  • Multi-source BFS for multiple goal cells to find shortest paths from all goals simultaneously.
  • Modeling portals as edges with zero or specified cost, or as teleportation nodes.
  • For all shortest paths, use BFS (unweighted) or Dijkstra with predecessor tracking, and discuss potential exponential number of paths.
  • Time and space complexity: O(V log V + E) for Dijkstra, O(V+E) for BFS.
  • Edge cases: negative weights (use Bellman-Ford), unreachable goals, and portals creating cycles.

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