generate every possible subset and check
\nclass Solution {\npublic:\n    int maximumRows(vector<vector<int>>& mat, int cols) {\n        int m=mat.size(),n=mat[0].size(),ans=0;\n        int mask=((1<<n
```\nclass Solution {\npublic:\n    int maximumRows(vector<vector<int>>& mat, int cols) {\n        int m=mat.size(),n=mat[0].size(),ans=0;\n        int mask=((1<<n)-1);\n        // use mask to generate every possible columns combination\n        while(mask){\n            unordered_set<int>select;\n            for(int i=0;i<n;i++){\n                if(((mask>>i)&1)==1)\n                    select.insert(i);\n            }\n            // if subset contains exaclty "cols" columns then we can use this subset\n            if(select.size()==cols){\n                int cnt=0;\n                for(int j=0;j<m;j++){\n                    bool flag=true;\n                    for(int k=0;k<n;k++){\n                        // if any row contains 1 in  column other than columns which we have in "select" then this row is not valid row for our answer\n                        if(mat[j][k]==1 && select.count(k)==0){\n                            flag=false;\n                            break;\n                        }\n                    }\n                    if(flag)\n                        cnt++;\n                }\n                ans=max(ans,cnt);\n            }\n            mask--;\n        }\n        return ans;\n    }\n};\n```\nDo **UPVOTE** is it helps :)
[]