← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding round with a grid traversal problem. Pretty classic BFS setup but the way they framed it with the move/canMove abstraction threw me off a bit at first.

Questions Asked (1)

Q1

Given a 2D grid maze with a start position and a cheese position, implement move() and canMove() functions and find the shortest path from start to cheese. Return -1 if no path exists.

Algorithms & Data Structures
Author's notes

The abstraction layer with move() and canMove() is what made this feel different from a plain BFS grid problem.

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 moves to adjacent open cells are edges. Use BFS to find the shortest path from start to cheese, leveraging the move() and canMove() functions to explore neighbors. If BFS exhausts all reachable cells without finding the cheese, return -1.

Pro tip: Clarify the maze representation and movement constraints upfront (e.g., 4-directional vs 8-directional, obstacles, grid size) to avoid incorrect assumptions. Discuss time and space complexity (O(R*C)) and mention potential optimizations like bidirectional BFS if the maze is large.

1. Understand the problem and constraints

Ask clarifying questions about the maze structure, movement rules, and the behavior of move() and canMove(). Confirm the goal is to find the shortest path length.

2. Design the algorithm

Choose BFS for shortest path in an unweighted grid. Explain how you'll track visited cells and distances, and how move() and canMove() will be used to navigate.

3. Implement move() and canMove()

Define move(direction) to update the current position if the move is valid, and canMove(direction) to check if moving in that direction is possible without hitting a wall or boundary.

4. Implement BFS to find shortest path

Initialize a queue with the start position and a distance map. While the queue is not empty, dequeue a cell, check if it's the cheese, and enqueue all valid unvisited neighbors using canMove() and move().

5. Handle edge cases and return result

If the cheese is unreachable, return -1. Otherwise, return the distance when the cheese is found. Test with cases like start equals cheese, no path, and large mazes.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue for BFS and a visited set to avoid cycles
  • Time and space complexity: O(R*C) where R and C are grid dimensions
  • Handle edge cases: start equals cheese, no path, blocked start/cheese
  • Encapsulate movement logic in move() and canMove() for modularity
  • Consider bidirectional BFS for optimization if maze is very large

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