Fewest Box Pushes for a Warehouse Robot to Reach a Target

Last updated: November 29, 2026

Quick Overview

A warehouse robot on a grid with walls '#', open cells '.', one box 'B', a target 'T', and its own start 'S' can walk freely but can only push the box by stepping into it from the opposite side. Return the minimum number of pushes needed to move the box onto the target, or -1.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A warehouse robot on a grid with walls '#', open cells '.', one box 'B', a target 'T', and its own start 'S' can walk freely but can only push the box by stepping into it from the opposite side. Return the minimum number of pushes needed to move the box onto the target, or -1.

A Google onsite state space search framed around warehouse robotics. The interviewer checks that you identify the true state (box and robot positions), that walking is free while pushes cost one, and that you pick 0-1 BFS or a nested reachability BFS accordingly.

What the Interviewer Expects
  • Define the state as (box position, robot position)
  • Treat walking moves as cost 0 and pushes as cost 1
  • Use a 0-1 BFS deque: cost-0 moves to the front, pushes to the back
  • Validate a push: the cell beyond the box must be open
  • Bound the state space at (rows * cols)^2
Key Topics to Cover
0-1 BFS
state space search
grid simulation
shortest path
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 reduce states by keeping only the robot's side of the box?
  • What if there are two boxes?
  • How would you reconstruct the push sequence for the robot controller?
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: grid of characters. The robot moves one cell in four directions into open cells (not walls, not the box). Moving toward the box when the box is adjacent pushes it one cell if the cell beyond is...

High-Level Design

State (br, bc, pr, pc). From a state, for each direction compute the robot's next cell. If it equals the box, this is a push: the box goes one further; valid if in bounds and not a wall; cost + 1, a...


Submit Your Answer
Markdown supported