Fewest Walls to Break to Cross a Server Room Grid

Last updated: November 29, 2026

Quick Overview

A server room is a grid where 0 is an open tile and 1 is a removable partition. Starting at the top left and moving in four directions, return the minimum number of partitions that must be removed to reach the bottom right tile.

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

0

0

0 solved


A server room is a grid where 0 is an open tile and 1 is a removable partition. Starting at the top left and moving in four directions, return the minimum number of partitions that must be removed to reach the bottom right tile.

Microsoft interviewers use this to see whether candidates recognize a 0-1 weighted graph and avoid a full Dijkstra. The signal is choosing 0-1 BFS with a deque and explaining why it preserves Dijkstra's ordering.

What the Interviewer Expects
  • Model tiles as nodes with edge weight equal to the destination tile's value
  • Recognize weights in {0, 1} and use 0-1 BFS
  • Push zero weight moves to the front and unit weight moves to the back
  • Handle a blocked start tile
  • State O(rows * cols) time
Key Topics to Cover
0-1 BFS
shortest paths
grids
deque
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
  • What if partitions have different removal costs?
  • What if you can remove at most k partitions and want the shortest path length?
  • How would you return which partitions to remove?
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: rectangular grid of 0 and 1 values.
  • Moves: up, down, left, right.
  • Entering a 1 tile costs one removal; 0 tiles are free.
  • Output: the minimum removals to reach the bottom right tile, cou...
High-Level Design

Each tile is a node and moving into tile t costs grid[t], either 0 or 1. Dijkstra would work, but with only two weights we can use a deque instead of a heap. Popping from the front always gives a no...


Submit Your Answer
Markdown supported