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
Coding & Algorithms
Software Engineer
Walmart Labs
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
BFS
state space search
grid problems
pruning
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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: ...


Submit Your Answer
Markdown supported