← Meta Interview Insights

Meta·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026Remote

Summary

Got a coding screen for a SWE role at Meta. One problem, maze pathfinding on a grid, pretty standard BFS/DFS territory but worth writing up.

Questions Asked (1)

Q1

Given an m x n grid where 0 is an empty cell and 1 is a wall, determine whether a path exists from a given start coordinate to a target coordinate. You can move up, down, left, or right, but cannot go out of bounds or through walls.

Algorithms & Data Structures
Author's notes

Classic reachability problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then choose BFS or DFS to traverse the grid from the start, marking visited cells to avoid cycles. If a path is found, return true; otherwise, return false after exploring all reachable cells.

Pro tip: Discuss trade-offs between BFS and DFS: BFS finds the shortest path and is often preferred for grid problems, while DFS uses less memory but may be slower for large grids. Mention that you can optimize space by modifying the grid in-place if allowed.

1. Clarify and Validate

Confirm grid dimensions, start and target coordinates, movement rules, and edge cases such as start or target being a wall or out of bounds.

2. Choose Traversal Method

Decide between BFS (queue) or DFS (stack/recursion) based on requirements like shortest path or memory constraints, and explain your choice.

3. Implement Traversal

Use a queue or stack to explore neighbors in four directions, checking bounds and walls, and mark visited cells to avoid revisiting.

4. Handle Termination

Return true if the target is reached; if the traversal exhausts all reachable cells without finding the target, return false.

5. Analyze Complexity

State time and space complexity: O(m*n) time and O(m*n) space in the worst case, and discuss potential optimizations.

Key Points to Mention

  • Use BFS for shortest path or DFS for memory efficiency, and justify your choice.
  • Mark visited cells to prevent infinite loops, either with a separate visited matrix or by modifying the grid in-place.
  • Check boundaries and wall conditions before enqueueing or recursing.
  • Handle edge cases: start equals target, start or target is a wall, or coordinates out of bounds.
  • Time complexity is O(m*n) since each cell is visited at most once.
  • Space complexity is O(m*n) for the queue/stack and visited set in the worst case.

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