30. Boolean Matrix
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
Simple problem just Identify the rows and columns containing at least one 1
and then completely replace all the elements in those rows and columns with 1
.
Here are the steps to do so:
Create two vectors r
and c
to keep track of rows and columns that should be converted to all 1s.
Iterate through the matrix to find cells with the value 1
.
For each cell with the value 1, set the corresponding entry in the r
and c
vectors to 1.
Iterate through the r
vector and convert rows to all 1s where r[i]
is 1.
Iterate through the c
vector and convert columns to all 1s where c[j]
is 1.
Time Complexity: O(N*M)
, where N
is the number of rows and M
is the number of columns in the matrix.
Auxiliary Space Complexity: O(N+M)
, where N
is the number of rows and M
is the number of columns in the matrix.
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.