Count Servers that Communicate

You are given a map of a server center, represented as an m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.

Return the number of servers that communicate with any other server.

Example 1
1 0
0 1
Inputgrid = [[1,0],[0,1]]
Output0
No servers can communicate with others.
Example 2
1 0
1 1
Inputgrid = [[1,0],[1,1]]
Output3
All three servers can communicate with at least one other server.

Constraints

  • m == grid.length
  • n == grid[i].length
  • 1 <= m <= 250
  • 1 <= n <= 250
  • grid[i][j] == 0 or 1

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate