The "Count Servers that Communicate interview question" is a grid connectivity problem. You are given an matrix representing a server map, where 1 means a server is present and 0 means it is not. Two servers can communicate if they are in the same row or the same column. You need to count the total number of servers that can communicate with at least one other server.
Meta, Oracle, and Google ask the "Count Servers that Communicate coding problem" to evaluate a candidate's ability to optimize a grid-based search. While you could use BFS or DFS, the problem can be solved much more efficiently using linear row and column counts. it tests "Array interview pattern" skills and the ability to find a minimal representation of grid properties.
This problem is best solved using Row and Column Frequency Counting.
rowCount of size and colCount of size .rowCount[r] and colCount[c].rowCount[r] > 1 OR colCount[c] > 1.Grid:
1 0
1 1
row0=1, row1=2.col0=2, col1=1.
Check servers:row0=1, col0=2. communicating!row1=2, col0=2. communicating!row1=2, col1=1. communicating!
Result: 3 servers.For grid problems where connectivity is based strictly on row/column alignment, avoid complex graph traversals. Use frequency arrays to store the "server density" of each axis. This is a common "Matrix interview pattern" optimization.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Number of Closed Islands | Medium | Solve | |
| Maximum Number of Fish in a Grid | Medium | Solve | |
| Number of Enclaves | Medium | Solve | |
| Detect Cycles in 2D Grid | Medium | Solve | |
| Surrounded Regions | Medium | Solve |