← Meta Interview Insights

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

IntermediatePrefer not to say
Jul 2026

Summary

Meta SWE coding round focused on a maze problem split into two staged tasks: fixing a buggy printer function and then implementing a BFS solver. The AI-assisted format meant you were dropped into an existing codebase rather than starting from scratch, which added a layer of 'read before you write' pressure I didn't fully appreciate until I was already in it.

Questions Asked (5)

Q1

You're given a buggy function that prints a 2D character grid representing a maze. The output comes out wrong (transposed, extra spaces, or extra blank lines). Find and fix the bug so the maze prints row by row with no extra whitespace.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The transposed loop thing is one of those bugs that looks fine at a glance because grid[c][r] is syntactically valid.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, reproduce the bug by running the function and comparing the output to the expected grid. Then, trace the code to identify the root cause—likely an off-by-one error, incorrect loop bounds, or misplaced newline—and fix it by ensuring each row is printed exactly once with no trailing spaces or extra blank lines.

Pro tip: After fixing, test with edge cases like a 1x1 grid, a single row, and a single column to catch boundary issues that might not appear in larger mazes.

1. Reproduce and Observe

Run the function with a sample maze and capture the actual output. Compare it to the expected output to pinpoint the exact discrepancies (e.g., transposed, extra spaces, blank lines).

2. Trace the Code

Walk through the code line by line, paying attention to loop indices, print statements, and newline handling. Identify where the output diverges from the expected pattern.

3. Identify the Bug

Determine the root cause: common issues include swapped row/column indices, using print with end=' ' causing trailing spaces, or printing an extra newline after the last row.

4. Implement the Fix

Correct the bug by adjusting loop bounds, swapping indices, or modifying print statements to ensure each row is printed exactly once with no extra whitespace.

5. Verify with Edge Cases

Test the fixed function with various maze sizes, including 1x1, 1xN, Nx1, and larger grids, to confirm the output is correct and free of extra whitespace.

Key Points to Mention

  • Off-by-one errors in loop bounds (e.g., using <= instead of <)
  • Row-major vs. column-major traversal (transposition bug)
  • Handling of newlines: avoid extra blank lines by not printing a newline after the last row
  • Trailing spaces: ensure no spaces are printed at the end of each row
  • Edge cases: test with 1x1, 1xN, Nx1 grids to catch boundary issues
  • Debugging techniques: print statements, debugger, or unit tests to isolate the bug

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

Q2

Implement a BFS-based function that finds the shortest path length from 'S' to 'E' in a 2D maze grid, moving only in four orthogonal directions. Return the number of moves, or -1 if no path exists.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

BFS was obvious enough but I fumbled the passability check.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (grid size, obstacles, start/end uniqueness) and then outline a BFS approach using a queue to explore level by level, tracking visited cells to avoid cycles. Emphasize that BFS guarantees the shortest path in an unweighted grid, and discuss time/space complexity before coding.

Pro tip: Mention that you can optimize space by marking visited cells in-place (e.g., changing 'S' or '.' to a wall) if the input can be mutated, but always ask the interviewer first. Also, consider using a deque for O(1) popleft operations and early termination when 'E' is found.

1. Clarify and Validate

Ask about grid dimensions, obstacle representation, whether 'S' and 'E' are guaranteed, and if diagonal moves are allowed. Confirm that the grid is unweighted and that we need the shortest path length in moves.

2. Choose BFS and Explain Why

State that BFS is ideal for unweighted shortest path problems because it explores nodes in increasing order of distance from the start. Contrast with DFS, which does not guarantee shortest paths.

3. Outline Algorithm and Data Structures

Describe using a queue (collections.deque) to store cells and their distances, a visited set or in-place marking to avoid revisiting, and direction vectors for the four moves. Mention early exit when 'E' is dequeued.

4. Analyze Complexity and Edge Cases

State time complexity O(R*C) since each cell is visited at most once, and space O(R*C) for the queue and visited set. Discuss edge cases: no path, start equals end, empty grid, and unreachable 'E'.

5. Code and Test

Write clean, modular code with helper functions for neighbors and bounds checking. Walk through a small example and test edge cases to verify correctness.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue (FIFO) for level-order traversal
  • Track visited cells to avoid infinite loops
  • Time complexity O(R*C), space O(R*C)
  • Early termination when 'E' is found
  • Handle edge cases: no path, start=end, invalid input

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

Q3

How would you reconstruct the actual path of cells visited, not just the length, and what changes in your bookkeeping to support that?

Algorithms & Data Structures
Author's notes

Didn't get deep into this one but the answer is straightforward: store a parent map alongside the visited set, then backtrack from 'E' to 'S' once you terminate.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that reconstructing the path requires storing parent pointers or predecessor information during the search, rather than just distances. Then describe how to backtrack from the target to the source using that bookkeeping, and mention any trade-offs in space or time.

Pro tip: Emphasize that the choice between storing parent pointers versus predecessor arrays depends on the graph representation and whether you need to reconstruct multiple paths; also note that for BFS, parent pointers give the shortest path, while for DFS they give a valid path but not necessarily shortest.

1. Identify the need for path reconstruction

Recognize that standard BFS/DFS only records distances or visited status, so to reconstruct the path you need additional information linking each node to its predecessor.

2. Choose the right bookkeeping structure

Decide between a parent array (for implicit graphs) or a map from node to predecessor (for explicit graphs), and ensure it is updated whenever a node is first discovered.

3. Update during traversal

When exploring neighbors, if a neighbor is unvisited, set its predecessor to the current node before adding it to the queue/stack.

4. Backtrack from target to source

Starting from the target node, follow the predecessor links until reaching the source, then reverse the collected nodes to get the path from source to target.

5. Discuss trade-offs and optimizations

Mention that storing predecessors adds O(V) space, and that for weighted graphs you might need to store the edge used; also note that if multiple shortest paths exist, this method returns one of them.

Key Points to Mention

  • Parent pointer array or predecessor map
  • Updating predecessor when a node is first discovered
  • Backtracking from target to source and reversing
  • Space complexity increase by O(V)
  • Difference between BFS (shortest path) and DFS (any path)
  • Handling multiple paths or early termination

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

Q4

What would you change if cells had non-uniform movement costs, or if some cells were zero-cost teleports?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Non-uniform costs means Dijkstra instead of BFS.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: identify the current algorithm (likely BFS or Dijkstra) and its assumptions (uniform or non-negative costs). Then explain how non-uniform costs require a priority queue (Dijkstra) and how zero-cost teleports introduce zero-weight edges, which can be handled by Dijkstra but may cause infinite loops if not careful. Finally, discuss trade-offs like time complexity, memory, and potential optimizations.

Pro tip: Mention that zero-cost edges can be handled by Dijkstra if you avoid revisiting nodes, but if teleports create cycles, you might need to detect and ignore them or use a modified algorithm like 0-1 BFS if costs are only 0 and 1. Also, consider using a visited set to prevent infinite loops.

1. Clarify the problem and assumptions

Ask about the graph representation, whether costs are non-negative, and if teleports are bidirectional or have constraints. Confirm the goal: shortest path from source to target.

2. Identify the impact on the algorithm

Explain that uniform BFS no longer works; non-uniform costs require Dijkstra's algorithm with a priority queue. Zero-cost edges mean edge weights can be 0, which Dijkstra handles if weights are non-negative.

3. Address zero-cost teleports and potential issues

Discuss that zero-cost edges can create cycles of zero total cost, potentially causing infinite loops if not handled. Use a visited set or process nodes only once when popped from the priority queue.

4. Analyze time and space complexity

Compare BFS O(V+E) to Dijkstra O((V+E) log V) with a binary heap. Mention that zero-cost edges don't change asymptotic complexity but may increase constant factors.

5. Discuss optimizations and alternatives

If costs are small integers, consider Dial's algorithm or 0-1 BFS. For zero-cost teleports, ensure the graph is preprocessed to avoid redundant edges or use union-find to collapse zero-cost connected components.

Key Points to Mention

  • Dijkstra's algorithm with a priority queue for non-uniform non-negative costs
  • Handling zero-weight edges: they are allowed in Dijkstra but require careful visited tracking
  • Potential infinite loops with zero-cost cycles and how to avoid them (visited set, cycle detection)
  • Time complexity trade-offs: BFS vs Dijkstra, and special cases like 0-1 BFS
  • Graph preprocessing: collapsing zero-cost connected components using union-find
  • Edge cases: negative costs (not allowed), teleports with constraints (e.g., one-way, limited uses)

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

Q5

Could an A* heuristic (like Manhattan distance) improve performance here, and what does it actually change about the complexity?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

It doesn't change the worst-case asymptotic bound, just the constant factor in practice by pruning nodes that are moving away from the target.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem context and the current algorithm's complexity. Then explain how an admissible heuristic like Manhattan distance can reduce the search space in A* compared to Dijkstra or BFS, and discuss the theoretical and practical complexity changes, including worst-case guarantees and average-case improvements.

Pro tip: Emphasize that the heuristic must be admissible and consistent to guarantee optimality, and mention that while worst-case complexity remains exponential, the practical performance gain can be dramatic—this shows you understand both theory and real-world impact.

1. Clarify the problem and baseline

Ask or state the specific problem (e.g., grid pathfinding) and the current algorithm's time and space complexity (e.g., Dijkstra O(E + V log V)).

2. Explain A* and heuristic role

Describe how A* uses f(n) = g(n) + h(n), and that Manhattan distance is admissible for grid movement, guiding search toward the goal.

3. Analyze complexity change

Discuss that worst-case complexity remains exponential (or O(b^d)), but the heuristic reduces the effective branching factor and explored nodes, often leading to near-linear performance in practice.

4. Address trade-offs and guarantees

Mention that optimality is preserved if h is admissible/consistent, but a poor heuristic can degrade to Dijkstra; also note memory overhead of priority queue.

5. Conclude with practical impact

Summarize that A* with Manhattan distance significantly improves performance for grid-based problems, but complexity depends on heuristic quality and problem structure.

Key Points to Mention

  • A* combines uniform-cost search with a heuristic to prioritize promising nodes.
  • Manhattan distance is admissible for 4-directional grid movement, ensuring optimality.
  • Worst-case time complexity remains exponential, but average-case improves due to reduced search space.
  • The heuristic reduces the effective branching factor, often making the search near-linear in practice.
  • Consistency (monotonicity) of the heuristic avoids re-expansion of nodes and ensures efficiency.
  • Trade-offs: memory usage and heuristic computation cost vs. speedup.

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