← Meta Interview Insights

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

SeniorPrefer not to say
Apr 2026Remote

Summary

Meta's AI-Enabled Coding round is a gauntlet of 4-5 progressive maze solver tasks where you're expected to drive the AI rather than just let it run. The bar for a strong signal is reaching the keys-and-doors problem; the bomb variant is basically extra credit. Explanation follow-ups after every AI-generated block will make or break you.

Questions Asked (6)

Q1

There's a bug in the maze printer where the path symbol overwrites the start and end markers in the output. Fix the display logic so S and E always take visual priority.

Algorithms & Data StructuresRoot Cause Analysis
Author's notes

Sounds trivial but I spent way too long on it because one of the test cases in the starter project is intentionally broken.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the current rendering logic and identify where the path symbol overwrites S and E. Then, propose a priority-based rendering approach that ensures S and E are always drawn last or checked first, and discuss how to implement it cleanly.

Pro tip: Mention that you would add a unit test to prevent regression, showing you care about maintainability and not just a quick fix.

1. Understand the current rendering order

Examine the code to see the sequence in which cells are printed, and identify where the path symbol is written over S and E.

2. Define priority rules

Establish that S and E have higher priority than the path symbol, and decide on a clear precedence order (e.g., S > E > path > wall).

3. Implement priority-based rendering

Modify the display logic to check for S and E first, or render them last, ensuring they are never overwritten.

4. Test and validate

Run the maze printer with various mazes to confirm S and E are always visible, and add a regression test.

Key Points to Mention

  • Root cause: path symbol is printed after S and E, overwriting them.
  • Solution: enforce rendering priority, e.g., by checking cell type before printing.
  • Consider edge cases: overlapping S/E with path, multiple paths, different maze sizes.
  • Maintain code readability and avoid special-case hacks.
  • Add unit tests to prevent future regressions.
  • Discuss time/space complexity if relevant, but focus on correctness.

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

Q2

The BFS search in the maze solver runs forever. Why, and how do you fix it?

Algorithms & Data Structures
Author's notes

Pretty straightforward once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, explain that BFS runs forever when the visited set is missing or incorrectly updated, causing cycles to be re-explored indefinitely. Then, describe the fix: mark nodes as visited when enqueuing them, not when dequeuing, and ensure the visited set is checked before adding neighbors to the queue.

Pro tip: Mention that marking visited at enqueue time prevents duplicate entries in the queue, which is a common subtle bug that can also cause exponential memory usage even if the search terminates.

1. Identify the symptom

Recognize that infinite BFS typically means the algorithm is revisiting nodes, often due to a missing or ineffective visited set.

2. Trace the cycle

Explain how cycles in the maze graph cause BFS to loop if nodes are not marked as visited, leading to an infinite queue.

3. Pinpoint the bug

State that the visited set is either not used, or nodes are marked visited only when dequeued, allowing duplicates to be enqueued.

4. Apply the fix

Mark nodes as visited immediately when they are enqueued, and check visited status before enqueuing neighbors.

5. Verify and discuss trade-offs

Confirm the fix prevents infinite loops and discuss how enqueue-time marking also optimizes memory and time.

Key Points to Mention

  • BFS explores level by level and requires a visited set to avoid cycles.
  • Marking visited at enqueue time prevents duplicate queue entries.
  • Marking visited at dequeue time can still cause infinite loops in cyclic graphs.
  • The visited set should be checked before adding a neighbor to the queue.
  • Infinite loops often stem from missing or misplaced visited checks.
  • Enqueue-time marking improves both correctness and efficiency.

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

Q3

The maze now has directional gate cells marked with > and <. Movements through those cells must follow the indicated direction. Update the neighbor logic to enforce this.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The tricky part is deciding where to apply the constraint: on entry to the gate cell or on exit from it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact movement rules for directional gates, then modify the neighbor-generation function to filter moves based on the gate's arrow. Keep the core BFS/DFS logic unchanged, and test with edge cases like gates at boundaries or conflicting directions.

Pro tip: Mention that you'd encapsulate the gate logic in a helper function to keep the main traversal clean and testable, and discuss how this change affects time/space complexity (still O(R*C) with constant extra work per cell).

1. Clarify the rules

Ask whether a gate cell allows only the indicated direction or also blocks entry from other directions. Confirm if gates can be at start/end and whether they override normal movement.

2. Identify the neighbor logic

Locate the function that generates valid neighbors for a given cell. This is typically where you check boundaries and obstacles.

3. Modify neighbor generation

For each candidate neighbor, if the current cell is a gate, only allow the move if it matches the gate's direction. Alternatively, if the neighbor is a gate, ensure the move direction is allowed by that gate.

4. Handle edge cases

Consider gates at the maze edges, multiple gates, and gates that might create dead ends. Ensure the algorithm still terminates and finds a path if one exists.

5. Test and analyze

Write unit tests for various gate configurations. Discuss time/space complexity: still O(R*C) since each cell is processed once, with O(1) extra check per neighbor.

Key Points to Mention

  • Directional gates restrict movement to a single direction (e.g., '>' means only move right).
  • Neighbor generation must check the gate's direction before adding a neighbor.
  • Encapsulate gate logic in a helper function for clarity and testability.
  • Maintain the same traversal algorithm (BFS/DFS) with minimal changes.
  • Consider both interpretations: gate restricts exit from the cell or entry into the cell.
  • Complexity remains O(R*C) time and space, with constant overhead per cell.

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

Q4

Add keys and doors to the maze. Lowercase letters are keys, uppercase letters are locked doors. You can only pass through a door if you've already picked up the matching key. How do you update the search state?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is the one that actually tests whether you understand BFS state space expansion.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that the search state must be augmented to include the set of keys collected so far, since the same position can be reachable with different key sets. Use BFS where each state is (position, key_bitmask), and only allow transitions through doors if the corresponding key bit is set. Discuss how this affects visited tracking and state space size.

Pro tip: Mention that using a bitmask for keys is efficient and that the state space becomes O(R*C*2^K), which is manageable for small K. Also note that you can precompute which keys are reachable without doors to optimize, but the core idea is state augmentation.

1. Define the state

The state should be (row, col, keys_bitmask), where keys_bitmask represents the set of keys collected. This captures all necessary information to determine valid moves.

2. Update visited tracking

Use a 3D visited array or a set of (row, col, keys_bitmask) to avoid revisiting the same state. A position alone is insufficient because different key sets enable different future paths.

3. Handle transitions

When moving to a new cell, if it's a key, update the bitmask by setting the corresponding bit. If it's a door, only allow the move if the matching key bit is already set.

4. Analyze complexity

The state space is O(R*C*2^K) where K is the number of distinct keys. BFS time and space are proportional to this, which is feasible for small K (e.g., K ≤ 10).

5. Consider optimizations

Mention that you can precompute connected components of open areas and keys, or use bidirectional BFS, but the bitmask state is the fundamental change.

Key Points to Mention

  • State must include the set of keys collected, not just position.
  • Use a bitmask to efficiently represent the key set.
  • Visited tracking must be per (position, key set) to avoid incorrect pruning.
  • Door traversal is conditional on having the matching key.
  • Time and space complexity increase by a factor of 2^K.
  • BFS is still appropriate; the state graph is just larger.

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

Q5

A bomb glyph has been added to the maze. Stepping on it destroys all walls within a fixed radius. Implement a helper that computes the affected area, and decide how to fold wall destruction into the search state.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

Reach territory, added recently from what I understand.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and define the bomb's effect precisely. Then, design a helper to compute affected walls and integrate it into the search state, likely by tracking bomb usage and modifying the graph dynamically. Finally, discuss trade-offs between precomputation and on-the-fly updates, and analyze complexity.

Pro tip: Demonstrate awareness of state-space explosion: if the bomb can be used multiple times, the state must include remaining bombs or a bitmask of destroyed walls. Also, consider that destroying walls may create shortcuts, so the search must adapt.

1. Clarify requirements and constraints

Ask about bomb radius, whether it can be used once or multiple times, if walls are permanently destroyed, and if the bomb affects only walls or also other entities. Confirm the goal: shortest path? minimum bombs?

2. Design the helper to compute affected area

Given a bomb position, iterate over all walls within the radius (e.g., using Manhattan or Euclidean distance) and mark them as destroyed. Optimize by precomputing wall positions in a grid or using spatial indexing if needed.

3. Integrate wall destruction into search state

Decide how to represent the modified maze in the search state. Options: include a bitmask of destroyed walls (if few), or recompute dynamically. Ensure the state captures enough to avoid revisiting equivalent configurations.

4. Choose and adapt search algorithm

Use BFS for unweighted grids, Dijkstra/A* for weighted. Modify the algorithm to consider bomb usage as an action that transitions to a new state with updated walls. Handle visited states carefully to account for different wall configurations.

5. Analyze complexity and trade-offs

Discuss time/space complexity with and without bomb. Compare precomputing all possible bomb effects vs. on-the-fly computation. Mention potential optimizations like bidirectional search or heuristic guidance.

Key Points to Mention

  • State representation: how to encode destroyed walls (bitmask, set, or modified grid) and bomb count.
  • Distance metric for bomb radius: Manhattan vs. Euclidean, and whether it affects walls in a square or circle.
  • Search algorithm adaptation: BFS with state, Dijkstra with dynamic edge weights, or A* with admissible heuristic.
  • Handling multiple bombs: if multiple, state must track which walls are destroyed and bombs remaining.
  • Complexity analysis: worst-case O(V+E) per bomb usage, but state space may grow exponentially.
  • Trade-offs: precomputing bomb effects for all positions vs. computing on demand; memory vs. time.

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

Q6

Alternatively: each cell has an energy cost. Find the path from start to exit that minimizes total energy consumed.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Dijkstra swap-in for the bomb variant.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (grid size, energy costs, movement directions) and then model it as a shortest path problem on a weighted graph. Discuss Dijkstra's algorithm as the optimal solution for non-negative weights, and compare it with BFS or A* if heuristics apply.

Pro tip: Mention that if energy costs are uniform, BFS suffices, but for arbitrary non-negative costs, Dijkstra's is necessary; also note that if negative costs exist, Bellman-Ford would be required, though that's unlikely in this context.

1. Clarify the problem

Ask about grid dimensions, movement directions (4-way or 8-way), whether energy costs are non-negative, and if the start and exit are fixed. Confirm that the goal is to minimize total energy consumed.

2. Model as a graph

Represent each cell as a node and possible moves as edges with weights equal to the energy cost of entering the destination cell. This transforms the problem into finding the shortest path from start to exit.

3. Choose the right algorithm

For non-negative weights, Dijkstra's algorithm is optimal. If all weights are equal, BFS is simpler and more efficient. If a heuristic like Manhattan distance is admissible, A* can speed up the search.

4. Analyze complexity and trade-offs

Dijkstra's with a priority queue runs in O(E log V) time, where E is edges and V is vertices. For a grid, this is O(N log N) where N is number of cells. Discuss space complexity and potential optimizations like early termination when the exit is reached.

5. Handle edge cases and test

Consider unreachable exit, negative costs (if allowed), and large grids. Walk through a small example to verify the approach and discuss potential pitfalls like integer overflow.

Key Points to Mention

  • Dijkstra's algorithm for non-negative weighted graphs
  • BFS for unweighted or uniform-cost grids
  • A* search with admissible heuristic (e.g., Manhattan distance)
  • Time and space complexity analysis
  • Handling of edge cases (unreachable exit, negative costs)
  • Trade-offs between different algorithms and data structures (e.g., priority queue implementation)

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