Warehouse Robot Shortest Path With Limited Pallet Moves
Last updated: November 29, 2026
Quick Overview
A warehouse floor is a grid of free cells and cells blocked by pallets. A robot starts at the top-left and must reach the bottom-right moving in four directions, and it may clear at most k pallets along the way. Return the minimum number of steps, or -1.
Walmart Labs
November 29, 20260
0
0 solved
A warehouse floor is a grid of free cells and cells blocked by pallets. A robot starts at the top-left and must reach the bottom-right moving in four directions, and it may clear at most k pallets along the way. Return the minimum number of steps, or -1.
Framed around autonomous floor robots in Walmart distribution and fulfillment centers. The Walmart Labs onsite interviewer looks for BFS over an expanded state of position plus remaining clears, with a pruning rule that keeps the state space manageable.
What the Interviewer Expects
- Recognize that position alone is not a sufficient BFS state
- Search over (row, col, clears remaining)
- Prune states dominated by an earlier visit with at least as many clears left
- Cap k at the length of a Manhattan path
- Return as soon as the target is reached in BFS order
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
- How would you use A* with a Manhattan heuristic here?
- What if clearing a pallet costs extra time rather than counting against a budget?
- How would you plan paths for several robots that must not collide?
- How does the solution change on a 2,000 by 2,000 grid?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a grid of strings with . for free and # for a pallet, and an integer k. Moving into a pallet cell uses one clear. The start and target cells also count if they hold pallets. Output: fewest ...
High-Level Design
Plain BFS on cells is wrong because reaching a cell with more clears left can matter later. Expand the state to (r, c, left). Every move costs one, so level-order BFS gives shortest steps. Pruning: ...