Boolean Matrix

PHOTO EMBED

Tue Nov 08 2022 05:54:38 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution
{   
    public:
    //Function to modify the matrix such that if a matrix cell matrix[i][j]
    //is 1 then all the cells in its ith row and jth column will become 1.
    void booleanMatrix(vector<vector<int> > &matrix)
    {
       
        int n1=matrix.size();
        int n2=matrix[0].size();
        vector<pair<int,int>> v;
        for(int i=0;i<n1;i++)
        {
            for(int j=0;j<n2;j++)
            {
                if(matrix[i][j]==1) 
                {
                    v.push_back({i,j});
                    
                }
            }
        }
        int n3=v.size();
        for(int i=0;i<n3;i++)
        {
            for(int j=0;j<n2;j++)
            {
                matrix[v[i].first][j]=1;
            }
            for(int j=0;j<n1;j++)
            {
                matrix[j][v[i].second]=1;
            }
        }
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/boolean-matrix-problem-1587115620/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article