PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Microsoft

Fill rooms with nearest-gate distance

Last updated: Mar 29, 2026

Quick Overview

This Coding & Algorithms question evaluates algorithmic problem-solving with grid-based graph traversal and shortest-distance computation, assessing data-structure use and implementation-level efficiency for software engineers.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Fill rooms with nearest-gate distance

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an m×n grid representing a building floor plan: - `-1` = wall/blocked cell - `0` = gate - A large positive number (e.g., `INF = 2^31-1`) = empty room Fill each empty room with the distance to its nearest gate (Manhattan distance: up/down/left/right). If a gate cannot be reached, leave the value as `INF`. Return the modified grid (or modify it in-place).

Quick Answer: This Coding & Algorithms question evaluates algorithmic problem-solving with grid-based graph traversal and shortest-distance computation, assessing data-structure use and implementation-level efficiency for software engineers.

Related Interview Questions

  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Implement SFT Sample Packing - Microsoft (medium)
  • Implement SQL Table and DNA Ordering - Microsoft (medium)
  • Solve power jumps and graph tour - Microsoft (hard)
Microsoft logo
Microsoft
Feb 7, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

You are given an m×n grid representing a building floor plan:

  • -1 = wall/blocked cell
  • 0 = gate
  • A large positive number (e.g., INF = 2^31-1 ) = empty room

Fill each empty room with the distance to its nearest gate (Manhattan distance: up/down/left/right). If a gate cannot be reached, leave the value as INF.

Return the modified grid (or modify it in-place).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.