Ctrl K

Servers Sharing a Line

Medium
A server hall is an m × n matrix hall: 1 means a server sits in that cell, 0 means the cell is empty. Two servers can talk to each other if they are in the same row or the same column, no matter how far apart. Return how many servers can talk to at least one other server.
Example 1
hall=[[1, 0, 1], [0, 0, 0], [0, 1, 0]] → 2

The two servers in the top row see each other. The server in the bottom row is alone in both its row and its column.

Example 2
hall=[[1, 1], [0, 1]] → 3

The top-right server shares a row with the top-left one and a column with the bottom one, so all three are connected.

Example 3
hall=[[0, 1], [1, 0]] → 0
Constraints
  • 1 ≤ m, n ≤ 250
  • hall[i][j] is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDrain the Landlocked Ponds MediumLand Regions on a Map MediumLargest Forest Patch MediumA Board Cut by Slashes MediumLandlocked Land Cells Medium
loading Python…
Input
hall=[[1, 0, 1], [0, 0, 0], [0, 1, 0]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 53 tests on the server, hidden ones included.