Largest Elements in Their Row and Column
You are given a two-dimensional list of integers matrix containing 1s and 0s. Return the number of elements in matrix such that:
matrix[r][c] = 1matrix[r][j] = 0for everyj ≠ candmatrix[i][c] = 0for everyi ≠ r
Constraints
0 ≤ n, m ≤ 250wherenandmare the number of rows and columns inmatrix
https://binarysearch.com/problems/Largest-Elements-in-Their-Row-and-Column
Examples
Example 1
Input
- matrix =
[[0,0,1],
[1,0,0],
[0,1,0]]
Output
- answer =
3
Explanation
We have matrix[0][2], matrix[1][0] and matrix[2][1] meet the criteria.
Example 2
Input
- matrix =
[[0,0,1],
[1,0,0],
[1,0,0]]
Output
- answer =
1
Explanation
Only matrix[0][2] meet the criteria. The other two 1s share the same column.
Leave a comment