You are given a two-dimensional list of integers grid with m rows and n columns. Every cell is either 0 or 1.
Call a cell equal to 1 linked if there is at least one other cell equal to 1 in the same row or in the same column.
Return the number of linked cells.
Examples
Example 1
Input: grid = [[1,0],[0,1]]
Output: 0
Explanation: The two 1 cells are at [0][0] and [1][1]. They are in different rows and different columns, so neither one is linked.
Example 2
Input: grid = [[1,0],[1,1]]
Output: 3
Explanation: The cells [0][0] and [1][0] share column 0. The cells [1][0] and [1][1] share row 1. Every 1 has another 1 in its row or column, so all three are linked.
Example 3
Input: grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]
Output: 4
Explanation: The two 1 cells in row 0 share a row. The two 1 cells in column 2 share a column. The cell [3][3] is the only 1 in row 3 and the only 1 in column 3, so it is not linked.
Constraints
m=grid.length
n=grid[i].length
1≤m≤250
1≤n≤250
grid[i][j] is 0 or 1
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run