←ENG-DSA-021Datacenter Network Partitions (Matrix DFS)
00:00
🐍 Python Idle
Mode:Web

Datacenter Network Partitions (Matrix DFS)

CompaniesGoogle, Cloudflare
Est. Time~30 min
LevelMid
MatrixDFSBFS
🚨 P0 Incident
GoogleCloudflare

Google's datacenter management system represents physical server racks as a 2D grid. After a switch failure, the network partitioned into isolated islands of servers. Each island requires a separate VLAN configuration and independent monitoring. The operations team needs an automated count of network partitions before dispatching field engineers.

πŸ“₯ Assigned to:You β€” Mid Engineer
Your Task

Our datacenter is represented as a 2D grid. `1` represents an active server rack, `0` represents an empty aisle. An "island" is a cluster of connected servers. Due to a switch failure, the network partitioned. Count how many isolated server clusters exist.

⏱ Time: O(M*N)πŸ’Ύ Space: O(min(M,N)) DFS stack
Example 1
Input:Β Β grid=[["1","1","1"],["1","1","0"],["0","0","0"]]
Output:Β 1
Example 2
Input:Β Β grid=[["1","0","0"],["0","1","0"],["0","0","1"]]
Output:Β 3
πŸ”’ +3 hidden test cases β€” revealed on Submit
Hints
Loading editor…
Test Output
β–Ά Run Code to test against examples Β· Submit to judge all 5 test cases
EngPrep β€” Real Engineering. Real Interviews.