← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Meta coding round, just one problem the whole time: the rolling ball maze. Felt manageable once I recognized the pattern but the follow-up on shortest distance tripped me up a bit.

Questions Asked (2)

Q1

Given a 2D grid with walls and empty cells, a ball rolls in one of four directions and only stops when it hits a wall or the grid boundary. Can the ball reach and stop exactly at a given destination cell?

Algorithms & Data Structures
Author's notes

I knew BFS would work here but I fumbled the transition logic at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a graph where each cell is a node, and rolling from a cell in a direction leads to another cell (where the ball stops). Use BFS to explore all reachable stopping positions from the start, and check if the destination is among them. Alternatively, use DFS with memoization to avoid revisiting states.

Pro tip: Clarify that the ball must stop exactly at the destination, not just pass through it. Also, mention that you can precompute the next stopping cell for each cell and direction to optimize the solution.

1. Understand the problem

Confirm that the ball rolls until it hits a wall or boundary, and must stop exactly at the destination. Identify the start and destination cells, and note that the ball cannot change direction mid-roll.

2. Model as a graph

Treat each cell as a node. From a cell, rolling in a direction leads to another cell where the ball stops. These directed edges form the graph.

3. Choose traversal algorithm

Use BFS to find the shortest path or DFS to check reachability. BFS is preferred for shortest path, but either works for reachability.

4. Implement rolling logic

For a given cell and direction, simulate rolling until hitting a wall or boundary. Record the stopping cell. Use precomputation or on-the-fly calculation.

5. Check destination and handle edge cases

After traversal, check if the destination is visited. Handle cases where start equals destination, or destination is unreachable.

Key Points to Mention

  • Graph representation: cells as nodes, directed edges for rolls.
  • BFS/DFS for reachability, with visited set to avoid cycles.
  • Simulation of rolling: iterate in direction until obstacle.
  • Time complexity: O(m*n) with precomputation, O(m*n*(m+n)) without.
  • Space complexity: O(m*n) for visited set and queue/stack.
  • Edge cases: start equals destination, destination is a wall, no path exists.

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

Q2

Now find the shortest distance for the ball to stop at the destination, not just whether it can reach it.

Algorithms & Data Structures
Author's notes

Switched from BFS to Dijkstra here and I think that was right, but I second-guessed myself out loud which probably looked bad.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each state represents the ball's position and velocity, then use BFS to find the shortest sequence of moves to reach the destination with zero velocity. Alternatively, if the ball moves continuously, use binary search on the distance to check if stopping is possible within that distance. Clearly state assumptions about the ball's motion and constraints.

Pro tip: Always clarify the problem constraints and edge cases (e.g., can the ball overshoot and come back? Are there obstacles?) before diving into a solution. This shows you think like a engineer who values correctness and completeness.

1. Clarify the problem

Ask questions to understand the ball's movement rules, the environment (grid, continuous space, obstacles), and what 'stop at destination' means (zero velocity at exact point).

2. Define state and transitions

Represent the state as (position, velocity) and define possible actions (e.g., accelerate left/right, apply force) that change the state.

3. Choose algorithm

For discrete states, use BFS to find shortest path to a goal state with zero velocity. For continuous, use binary search on distance with a feasibility check (e.g., can we stop within D?).

4. Implement and optimize

Code the solution, handle edge cases (e.g., unreachable destination), and discuss time/space complexity. Optimize if needed (e.g., bidirectional BFS, A*).

5. Test and validate

Walk through examples, test edge cases, and verify the solution returns the shortest distance. Discuss potential pitfalls and how to address them.

Key Points to Mention

  • State-space search (position, velocity) and BFS for shortest path
  • Binary search on answer for continuous problems
  • Handling of overshoot and deceleration to stop exactly at destination
  • Time and space complexity analysis
  • Edge cases: unreachable destination, obstacles, infinite loops
  • Alternative approaches (e.g., dynamic programming, Dijkstra) and trade-offs

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