Time Until Malware Spreads Across a Datacenter Server Grid

Last updated: November 29, 2026

Quick Overview

A datacenter row is modeled as a grid where each cell is empty, a healthy server, or a compromised server; every minute each compromised server infects its four neighbors. Return the minutes until every server is compromised, or -1 if some server can never be reached.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


A datacenter row is modeled as a grid where each cell is empty, a healthy server, or a compromised server; every minute each compromised server infects its four neighbors. Return the minutes until every server is compromised, or -1 if some server can never be reached.

A multi-source BFS question in the style of Microsoft online assessments, framed around lateral movement that Microsoft Defender tries to model. The grader looks for simultaneous BFS from every source rather than one BFS per infected server, and careful counting of layers.

What the Interviewer Expects
  • Seeds the queue with all compromised servers at once
  • Counts minutes by BFS layers, not by nodes
  • Tracks remaining healthy servers to detect unreachable ones
  • Avoids mutating input or explains that it does
  • States O(R * C) time and space
Key Topics to Cover
Multi-source BFS
Grid traversal
Level-order processing
Reachability
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
  • Servers have different patch levels so infection takes 1 to 5 minutes per hop: what changes?
  • Return the minute at which each server was compromised.
  • You can isolate one server before the spread starts: which one minimizes total infected?
  • The grid is too large for memory: how would you process it in tiles?
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

Cells: 0 empty, 1 healthy, 2 compromised. Spread is 4-directional, one hop per minute. Return the minute when the last healthy server falls, 0 if none are healthy to begin with, and -1 if any healthy ...

High-Level Design

Each server's infection time is its shortest distance to the nearest compromised server. Running BFS from every source separately would cost O((R * C)^2). Instead put all sources in the queue at time ...


Submit Your Answer
Markdown supported