Problems/1267. Count Servers That Communicate

1267. Count Servers That Communicate

MediumMatrixGraphArrayCounting

Given an m x n grid representing a network of servers, where 1 represents a server and 0 represents empty space, determine how many servers can communicate.

Two servers are able to communicate if they are located in the same row or in the same column. Servers that are isolated in both their row and column cannot communicate.

Example 1
Input: grid = [ [1, 0], [0, 1] ]
Output: 0
Neither server can communicate because there is no other server in their respective rows or columns.
Example 2
Input: grid = [ [1, 0], [1, 1] ]
Output: 3
All three servers can communicate: (0,0) and (1,0) are in the same column, while (1,0) and (1,1) are in the same row.
Example 3
Input: grid = [ [1, 1, 0], [0, 0, 1], [0, 0, 1] ]
Output: 4
Servers at (0,0) and (0,1) communicate via row. Servers at (1,2) and (2,2) communicate via column.
Visualizer

Visualizer will appear here