The Shortest Path in a Hidden Grid interview question is an interactive problem where you control a robot on an unknown grid. You can call four API functions to move the robot: move(dir) which returns true if the move succeeded (cell is open) or false (cell is blocked), and you must navigate from a starting cell to a target cell. Find the shortest path to the target without knowing the grid in advance.
Meta and Bloomberg ask this interactive graph problem because it models real-world robotics and exploration algorithms: a robot with sensor-only navigation must map its environment and find the shortest path simultaneously. It tests DFS for exploration (map the grid) followed by BFS for shortest path computation — a complete search-then-plan architecture used in autonomous navigation systems.
The pattern is DFS exploration followed by BFS pathfinding. Phase 1 — DFS to build the map: start from the initial position (treat as origin (0,0)). Try all 4 directions. If move(dir) returns true, mark the cell as open in a local grid, recurse, then backtrack (move in the opposite direction). If it returns false, mark as blocked. Also mark the target cell (when isTarget() returns true). Phase 2 — BFS on the mapped grid from (0,0) to the target cell. Return the BFS distance.
Hidden grid:
_ S _ _
_ _ 1 _
_ _ _ T
Robot starts at S. DFS explores all reachable cells, marking open/blocked. Target T discovered at relative position (2,2).
After DFS maps the reachable area, BFS from (0,0) to (2,2) finds shortest path: 4 steps (avoiding obstacle at (1,2)).
For the Shortest Path in a Hidden Grid coding problem, the DFS BFS matrix interactive interview pattern is the two-phase approach. The DFS exploration phase must include careful backtracking — practice the robot's movement: move forward, recurse, then move back. Bloomberg interviewers test the "always backtrack" discipline in DFS. Use a dictionary to store discovered cells by relative coordinate. After exploration, run standard BFS on the discovered map. This "explore then plan" pattern models the robot vacuum cleaner problem — a closely related interactive interview problem worth studying alongside this one.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find All Groups of Farmland | Medium | Solve | |
| Pacific Atlantic Water Flow | Medium | Solve | |
| The Maze | Medium | Solve | |
| Shortest Bridge | Medium | Solve | |
| Minesweeper | Medium | Solve |