Shortest Warehouse Robot Path When It Can Clear K Obstacles
Last updated: November 29, 2026
Quick Overview
A warehouse floor is a grid of 0 (open) and 1 (pallet obstacle). A robot moves up, down, left or right from the top-left cell to the bottom-right cell, and can clear at most k obstacles along the way. Return the minimum number of moves, or -1 if impossible.
Amazon
November 29, 20260
0
0 solved
A warehouse floor is a grid of 0 (open) and 1 (pallet obstacle). A robot moves up, down, left or right from the top-left cell to the bottom-right cell, and can clear at most k obstacles along the way. Return the minimum number of moves, or -1 if impossible.
An Amazon Robotics flavored state-space search question for onsite rounds. The interviewer checks that you extend BFS state to include remaining clears, prune with the best remaining-k per cell, and spot the Manhattan-distance shortcut when k is large.
What the Interviewer Expects
- Model state as (row, col, clears_left)
- Use BFS since every move costs 1
- Prune states dominated by a visit with more clears left
- Short-circuit when k >= rows + cols - 2
- Explain why plain visited-by-cell is wrong
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
- What if clearing an obstacle costs extra time instead of one move?
- How would you plan for many robots without collisions?
- How would you return the path itself?
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 is non-empty, start and end cells are open. 0 <= k. Return an int number of moves....
High-Level Design
Plain BFS with a visited set per cell fails, because reaching a cell with more clears left is strictly better than reaching it earlier with fewer. So the state is (r, c, remaining). BFS by levels stil...