← Meta Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round built around a progressive maze solver problem, starting from bug fixes and working up to BFS with keys and doors. Four parts in one session, each layering on the last. It's the kind of problem that feels manageable until part 3 and 4 show up.

Questions Asked (4)

Q1

You're given a buggy maze-solver codebase with failing unit tests. Fix the bugs without changing the intended behavior so all tests pass.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Started here and it was actually a decent warmup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by running the tests to identify failures, then systematically debug each issue by tracing the code and understanding the intended behavior from the tests and documentation. Fix bugs one at a time, ensuring that changes are minimal and do not alter the intended behavior, and re-run tests after each fix to confirm progress.

Pro tip: Before making any changes, read the test cases thoroughly to understand the expected behavior; they are your specification. Also, use a debugger or print statements to trace the code's execution rather than guessing.

1. Understand the code and tests

Read the problem statement, the code, and the unit tests to grasp the intended behavior and identify what the tests expect. Run the tests to see which ones fail and get initial error messages.

2. Isolate and diagnose bugs

For each failing test, trace the code execution to locate the root cause. Use debugging tools or add temporary logging to inspect variables and control flow.

3. Fix bugs incrementally

Make minimal changes to fix one bug at a time, ensuring the fix aligns with the intended behavior. Avoid altering unrelated code to prevent introducing new issues.

4. Verify with tests

After each fix, re-run the tests to confirm the specific failure is resolved and no regressions occur. Continue until all tests pass.

5. Review and refactor if needed

Once all tests pass, review the changes for clarity and maintainability. If time permits, consider if any refactoring can improve the code without changing behavior.

Key Points to Mention

  • Reading and understanding the unit tests as the specification for intended behavior
  • Using a systematic debugging approach (e.g., binary search, print statements, debugger)
  • Making minimal, targeted fixes to avoid unintended side effects
  • Running tests frequently to validate fixes and catch regressions early
  • Considering edge cases and ensuring the fix handles them correctly
  • Communicating the debugging process and rationale for each change

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

Q2

Implement BFS to find the shortest path from start to exit in the maze. Return -1 or None if no path exists.

Algorithms & Data Structures
Author's notes

Standard BFS, nothing tricky here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the maze as a graph where each cell is a node and edges connect adjacent open cells. Use BFS with a queue to explore level by level, tracking visited cells and distances, and return the distance when the exit is reached or -1/None if the queue empties.

Pro tip: Clarify the maze representation and movement rules upfront (e.g., 4-directional vs 8-directional, start/exit symbols) to avoid incorrect assumptions. Mention that BFS guarantees the shortest path in unweighted graphs, and consider edge cases like start equals exit or no path.

1. Clarify the problem

Ask about the maze format (2D array, characters), movement directions, and what constitutes a valid path. Confirm return type for no path (-1 or None).

2. Set up BFS

Initialize a queue with the start cell and a visited set or distance matrix. Define directions (e.g., up, down, left, right).

3. Explore level by level

While the queue is not empty, dequeue a cell, check if it's the exit, and if not, enqueue all valid unvisited neighbors with distance+1.

4. Handle termination

If exit is found, return its distance. If queue empties without finding exit, return -1 or None as specified.

5. Analyze complexity

State time and space complexity: O(R*C) for both, where R and C are maze dimensions, since each cell is visited at most once.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue (FIFO) for level-order traversal
  • Track visited cells to avoid cycles and redundant work
  • Distance can be stored in a separate matrix or as part of queue elements
  • Edge cases: start equals exit, no path, empty maze
  • Time and space complexity: O(R*C)

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

Q3

Extend the movement logic to enforce directional constraints on which moves are valid. Update the neighbor function accordingly and still return the shortest feasible path.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where it got a bit hairy.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the directional constraints and how they affect valid moves from each cell. Then, modify the neighbor function to only return moves that satisfy those constraints, and run BFS to find the shortest feasible path. Discuss trade-offs such as handling unreachable targets and potential optimizations.

Pro tip: Explicitly state that BFS remains optimal because all moves have equal cost, and mention that if constraints are dynamic or weighted, you might need Dijkstra or A*. This shows you understand algorithm selection beyond the basics.

1. Clarify constraints and assumptions

Ask clarifying questions to understand the exact directional rules (e.g., can you only move right and down? Are there forbidden turns?) and confirm that the goal is still shortest path in terms of number of moves.

2. Redefine neighbor function

Update the neighbor function to generate only moves that comply with the directional constraints. Ensure it checks the current direction (if stateful) or simply filters based on allowed directions from the current cell.

3. Choose and justify search algorithm

Use BFS for unweighted grids to guarantee shortest path. Explain that BFS explores level by level, so the first time you reach the target, it's via the shortest feasible path.

4. Handle edge cases and unreachable targets

Consider cases where no path exists due to constraints, and return an appropriate value (e.g., -1 or empty list). Also handle start equals target and out-of-bounds moves.

5. Analyze complexity and potential optimizations

State time and space complexity (O(V+E) for BFS). Mention possible optimizations like bidirectional BFS or A* if heuristics are available, and discuss trade-offs.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Neighbor function must enforce directional constraints
  • State may need to include direction if constraints depend on previous move
  • Time and space complexity analysis (O(V+E))
  • Handling unreachable targets and edge cases
  • Trade-offs between BFS, Dijkstra, and A* for different constraint types

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

Q4

Extend the maze to support keys (a-f) and locked doors (A-F). You collect a key by stepping on it and can only pass through a door if you hold the matching key. Modify BFS state to track collected keys and return the shortest path from start to exit.

Algorithms & Data StructuresSystem Design
Author's notes

The bitmask thing for tracking keys is something I'd seen before but blanked on under pressure and started reaching for a frozenset.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the state as (row, col, keys_bitmask) where keys_bitmask is a 6-bit integer representing collected keys. Run BFS over this expanded state space, updating the bitmask when stepping on a key and only moving through a door if the corresponding bit is set. Return the distance when reaching the exit.

Pro tip: Emphasize that the state space is bounded by rows × cols × 2^6, so BFS remains efficient; also mention that you can optimize by only tracking keys that are actually present in the maze.

1. Define the state representation

Represent each state as (row, col, keys_bitmask), where keys_bitmask uses bits 0-5 for keys a-f. This captures all necessary information to determine valid moves.

2. Initialize BFS

Start BFS from the start position with an empty key bitmask (0). Use a queue to store states and a visited set or 3D array to track visited (row, col, bitmask) combinations.

3. Process moves and update state

For each state, explore four directions. If the next cell is a wall, skip. If it's a key, update the bitmask by setting the corresponding bit. If it's a door, only proceed if the matching key bit is set. Otherwise, move normally.

4. Track distance and terminate

Maintain a distance counter (e.g., level-order traversal). When the exit cell is reached, return the current distance as the shortest path length.

5. Handle unreachable exit

If BFS exhausts all states without reaching the exit, return -1 or indicate no path exists.

Key Points to Mention

  • State space expansion: (row, col, keys_bitmask) ensures we don't revisit states with different key sets.
  • Bitmask operations: use bitwise OR to add a key and bitwise AND to check for a key.
  • BFS guarantees shortest path because all edges have equal weight.
  • Visited tracking: use a 3D boolean array or a set of encoded integers to avoid revisiting states.
  • Time complexity: O(rows * cols * 2^K) where K is the number of keys (≤6), which is efficient.
  • Space complexity: O(rows * cols * 2^K) for the visited structure and queue.

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