← Meta Interview Insights

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

SeniorPrefer not to say
May 2026

Summary

Meta SWE coding round, maze problem that kept growing. Four progressive stages, each one building on the last, and by the end I was genuinely not sure if I'd handled the state tracking correctly.

Questions Asked (4)

Q1

You're given a buggy maze solver codebase. The maze is a 2D grid with start, target, open cells, and walls. Fix the existing implementation so the provided unit tests for basic traversal pass.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Debugging someone else's code under pressure is its own skill and I don't practice it enough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by running the provided unit tests to identify failing cases, then trace the code to locate logical errors in traversal, boundary checks, and visited-state handling. Fix the minimal set of issues to make tests pass, explaining your debugging process and verifying edge cases.

Pro tip: Before changing any code, articulate the expected behavior of each test and use a debugger or print statements to confirm your hypothesis about the bug. This shows structured debugging and avoids random edits.

1. Understand the problem and tests

Read the problem statement and the provided unit tests to clarify the maze representation, movement rules, and expected outputs. Identify which tests are failing and what they assert.

2. Reproduce and isolate the failure

Run the tests to see the exact failures, then add logging or use a debugger to trace the solver's execution on a minimal failing case. Narrow down the bug to a specific function or condition.

3. Diagnose the root cause

Compare the code's logic against the correct algorithm (e.g., BFS/DFS) and check for common mistakes: off-by-one boundaries, missing visited checks, incorrect neighbor generation, or wrong start/target handling.

4. Implement and verify the fix

Make the minimal code change to correct the bug, then re-run all tests to ensure they pass. If needed, add temporary assertions or edge-case tests to confirm robustness.

5. Explain and reflect

Summarize the bug, your fix, and how you verified it. Mention any trade-offs (e.g., time/space complexity) and potential improvements for production code.

Key Points to Mention

  • Correct traversal algorithm (BFS/DFS) and data structures (queue/stack, visited set)
  • Boundary conditions and wall/start/target checks
  • Visited-state management to avoid infinite loops
  • Debugging methodology: hypothesis, isolation, minimal reproduction
  • Time and space complexity of the solution
  • Testing strategy: unit tests, edge cases, and regression prevention

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

Q2

Implement a BFS-based shortest path search on the maze that returns the minimum number of moves from S to T, or -1 if T is unreachable.

Algorithms & Data Structures
Author's notes

This part felt fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the maze as an unweighted graph where each cell is a node and edges connect adjacent open cells. Use BFS from the start cell S, tracking distances, and return the distance when T is reached or -1 if the queue empties without finding T.

Pro tip: Clarify edge cases upfront (e.g., S == T, no path, invalid input) and mention that BFS guarantees shortest path in unweighted graphs, showing you understand the algorithm's properties.

1. Clarify problem and constraints

Ask about maze representation (grid of chars, 0/1, etc.), movement allowed (4-directional or 8-directional), and whether S and T are guaranteed to exist. Confirm that each move costs 1.

2. Set up BFS data structures

Use a queue for BFS, a 2D array or hash set to track visited cells, and a distance map or store distance in the queue. Initialize with S and distance 0.

3. Perform BFS traversal

While queue is not empty, dequeue a cell, check if it's T (return distance), and enqueue all valid unvisited neighbors with distance+1. Mark visited when enqueuing to avoid duplicates.

4. Handle termination and return result

If T is never reached, return -1. Also handle edge case where S == T by returning 0 immediately.

5. Analyze complexity and test

State time and space complexity: O(R*C) for both, where R and C are maze dimensions. Walk through a small example to verify correctness.

Key Points to Mention

  • BFS explores level by level, ensuring the first time we reach T it's via the shortest path.
  • Use a queue (FIFO) and mark cells as visited when enqueuing to prevent revisiting and infinite loops.
  • Time and space complexity are O(R*C) for an R x C maze, since each cell is processed at most once.
  • Handle edge cases: S == T (return 0), T unreachable (return -1), and invalid inputs.
  • Avoid recursion (DFS) because it doesn't guarantee shortest path and may cause stack overflow.
  • Consider using a distance array initialized to -1 to track visited and distance simultaneously.

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

Q3

Extend the maze solver to enforce movement restrictions, where certain moves are disallowed based on the direction of the previous move or rules tied to the current cell.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I started fumbling.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the movement restrictions and how they interact with the existing maze solver. Then, model the problem as a state-space search where the state includes the current cell and the previous move direction, and adapt BFS/DFS accordingly. Discuss trade-offs between different approaches and ensure the solution handles edge cases.

Pro tip: Explicitly define the state representation early and discuss how it affects complexity; this shows you understand that adding constraints often requires augmenting the state, a key insight for scalable solutions.

1. Clarify the rules

Ask questions to fully understand the movement restrictions: Are they based on the previous move direction, current cell, or both? Are they deterministic? Can they be precomputed?

2. Define the state

Determine what information is needed to represent the state. Typically, this includes the current cell and the direction of the previous move (or a sentinel for the start).

3. Adapt the search algorithm

Modify BFS or DFS to incorporate the restrictions. When exploring neighbors, check if the move is allowed based on the current state and the rules.

4. Analyze complexity and trade-offs

Discuss how the state space size changes (e.g., from O(V) to O(V*D) where D is number of directions). Compare BFS vs DFS and consider optimizations like bidirectional search or A* if applicable.

5. Test and validate

Walk through edge cases: start cell, goal cell, dead ends, cycles. Ensure the solution correctly handles restrictions and terminates.

Key Points to Mention

  • State augmentation: including previous move direction in the state to enforce restrictions.
  • Graph representation: nodes as (cell, direction) pairs, edges as valid moves.
  • Algorithm choice: BFS for shortest path, DFS for any path, and how restrictions affect optimality.
  • Complexity analysis: time and space complexity with the augmented state.
  • Edge cases: start with no previous move, goal reachability, and cycles.
  • Trade-offs: precomputing allowed moves vs on-the-fly checks, and memory vs time.

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

Q4

Add key and door mechanics to the maze. Lowercase letters are keys, uppercase letters are doors that require the matching key to pass. The solver must still return the minimum move count to reach the target.

Algorithms & Data StructuresSystem Design
Author's notes

State explosion.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the maze as a graph where each state includes the current position and the set of keys collected. Use BFS to find the shortest path to the target, since each move has uniform cost. When encountering a door, only proceed if the corresponding key is in the collected set.

Pro tip: Mention that the state space can be optimized by only tracking keys that are actually present in the maze, and use bitmasking to represent key sets efficiently. Also, discuss how to handle multiple keys of the same type and doors that may be opened later.

1. Define the state

Represent each state as (row, col, keys_collected), where keys_collected is a bitmask or set of keys obtained so far. This captures all necessary information to determine valid moves.

2. Initialize BFS

Start BFS from the initial position with an empty key set. Use a queue to process states level by level, ensuring the first time we reach the target is the minimum moves.

3. Handle moves and key collection

For each state, explore all four directions. If the next cell is a wall, skip. If it's a key, add it to the key set. If it's a door, only proceed if the matching key is held.

4. Track visited states

Use a visited set to avoid revisiting the same (row, col, keys) state. This prevents cycles and ensures efficiency.

5. Return the result

If BFS reaches the target, return the number of moves. If the queue is exhausted without reaching the target, return -1 to indicate it's impossible.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs.
  • State space includes position and key set, increasing complexity.
  • Bitmasking for efficient key set representation.
  • Handling doors: only pass if key is collected.
  • Visited set must include key set to avoid missing paths.
  • Time complexity: O(R * C * 2^K) where K is number of keys.

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