← 返回 pinterest 的题目列表Robot Vacuum 8-Direction Grid
类型:qbank
Three-part robot-traversal grid problem: a vacuum starts at a position and can move in 8 directions (orthogonal + diagonal). Return all reachable cells in three settings — open grid, single-obstacle grid, and two cooperating vacuums.
Requirements
A robot vacuum starts in a 2-D grid and can move to any of the eight surrounding cells. Solve three forms in order:
Return all cells reachable in an open grid.
Add a blocked cell and return the reachable set.
Add a second vacuum and define whether the output is the union of independent reachable sets or an optimized coordinated coverage plan.
Notes
Use BFS or DFS with an eight-direction neighbor table and a visited set. For the blocked-cell form, exclude obstacles during neighbor generation.
The two-vacuum form is ambiguous by design. Independent traversal has the same reachable union as one traversal in a connected grid; collision avoidance or minimum coverage time creates a joint-state or scheduling problem. Clarify which contract applies.
A single obstacle rarely disconnects an eight-neighbor grid; test narrow boundaries and small grids where the obstacle can actually block movement.
Preparation
Implement the neighbor helper and traversal once, then add obstacle filtering.
Test 1×1, 1×N, corner-start, and blocked-neighbor cases.
State the two-vacuum clarification question and sketch both independent-union and coordinated-state solutions.