Skip to content

1267. Count Servers that Communicate #1214

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We'll follow these steps:

Approach:

  1. Count Servers in Each Row and Column:

    • Traverse the grid and calculate how many servers exist in each row and each column. This can be done using two arrays rowCount and colCount, where:
      • rowCount[i] stores the number of servers in row i.
      • colCount[j] stores the number of servers in column j.
  2. Check for Communication:

    • For each server in the grid, check if it can communicate with any other server by checking the rowCount and colCount. If either is greater than 1, then the server can communicate with others.
  3. Count the Servers that Communicate:

    • Traverse through the grid again and for each server (cell with value 1), check if it belongs to a row o…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Jan 23, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jan 23, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants