Skip to content

Practice Count Servers that Communicate

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1267
LeetCode Problem

Count Servers that Communicate

Problem Statement

You are given a map of a server center, represented as a 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.

Source: Count Servers that Communicate on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,0],[0,1]]
Output
0

# Example 2

Input
grid = [[1,0],[1,1]]
Output
3

# Example 3

Input
grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]
Output
4

Constraints

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

Related LeetCode Problems

Practice more problems similar to Count Servers that Communicate.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.