Shortest Robot Path Across a Warehouse Clearing Up to K Obstacles

Last updated: November 29, 2026

Quick Overview

A warehouse robot in a Microsoft datacenter moves on a grid of free (0) and blocked (1) cells in four directions. It may clear at most k blocked cells along the way. Return the fewest moves from the top-left to the bottom-right cell, or -1 if unreachable.

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

0

0

0 solved


A warehouse robot in a Microsoft datacenter moves on a grid of free (0) and blocked (1) cells in four directions. It may clear at most k blocked cells along the way. Return the fewest moves from the top-left to the bottom-right cell, or -1 if unreachable.

A BFS over an augmented state space, the kind of Hard grid problem Microsoft onsites use to test modeling. The interviewer checks that you add the remaining-clearance budget to the state, and that you prune states dominated by a better budget at the same cell.

What the Interviewer Expects
  • Recognize that position alone is not enough state
  • Use BFS over (row, col, remaining k)
  • Track the best remaining budget seen per cell to prune
  • Return the distance when the goal is first dequeued
  • Note the shortcut when k is at least R + C - 2
Key Topics to Cover
BFS
state space search
grids
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 handle different costs for clearing different obstacles?
  • What if the robot must return the list of cleared cells?
  • How would A* change the search here?
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 0s and 1s, R x C, start (0,0) and goal (R-1,C-1), integer k >= 0. Each move costs 1 regardless of clearing. Output: minimal moves or -1. Start and goal cells are free....

High-Level Design

Plain BFS fails because two arrivals at the same cell with different leftover budgets are not interchangeable. The state becomes (r, c, left). BFS by layers gives shortest moves. Moving into a block...


Submit Your Answer
Markdown supported