Shortest Path Across a Datacenter Floor Moving at Most K Racks
Last updated: November 29, 2026
Quick Overview
A robot crosses a datacenter floor grid from the top-left to the bottom-right cell, moving in four directions; cells are open (0) or occupied by racks (1). It may pass through at most k rack cells (by having them moved). Return the minimum number of moves, or -1.
OpenAI
November 29, 20260
0
0 solved
A robot crosses a datacenter floor grid from the top-left to the bottom-right cell, moving in four directions; cells are open (0) or occupied by racks (1). It may pass through at most k rack cells (by having them moved). Return the minimum number of moves, or -1.
Grid search with an extra resource is a standard OpenAI onsite pattern, and a datacenter floor is a natural framing given how much of the company's work runs on its own compute buildouts. The interviewer checks that you expand the state to include remaining breaks, avoid the wrong 'visited per cell' pruning, and justify why BFS still finds the shortest path.
What the Interviewer Expects
- Expand the BFS state to (row, col, breaks_left)
- Explain why marking a cell visited once is wrong
- Revisit a cell only with strictly more breaks remaining
- Cap k at the length of a monotone path as an optimization
- Handle blocked start or destination cells consistently
- Give complexity O(R * C * k)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Moving a rack costs 5 moves instead of 1: how does the algorithm change?
- Find the path that uses the fewest breaks, then the fewest steps.
- The floor is 10,000 by 10,000: how would you speed this up with A*?
- Several robots share the floor at once: what new problem appears?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
grid[r][c]is 0 or 1; move up, down, left or right inside the grid.- Entering a 1 cell consumes one break; the start and destination count if blocked.
- Output: fewest moves to reach the bottom-r...
High-Level Design
The state is position plus breaks remaining. BFS by levels gives the shortest number of moves because each move costs 1. Visiting a cell once is not enough: reaching it later with more breaks left can...