Bit Masking
Idea : Generate all possible combinations to select columns, then check what asked.\ni\'th bit in mask is set if we are considering taking that column, otherwis
**Idea** : Generate all possible combinations to select columns, then check what asked.\n*i\'th* bit in mask is set if we are considering taking that column, otherwise it will be zero.\n-Total of \'2 power columns\' `(1<<total_columns)` combinations are possible.\n\n```\nclass Solution {\n\n    public int maximumRows(int[][] mat, int cols) {\n        int max = 0;\n        for (int mask = 0; mask < (1 << mat[0].length); mask++) {\n            if (Integer.bitCount(mask) != cols) continue; // restricted to select ony cols columns\n            int c = 0;\n            for (int i = 0; i < mat.length; i++) {\n                boolean take = true;\n                for (int j = 0; j < mat[0].length; j++) {\n                    if ((mask >> j & 1) == 0 && mat[i][j] == 1) {\n                        take = false;\n                        break;\n                    }\n                }\n                if (take) c++;\n            }\n            max = Math.max(max, c);\n        }\n        return max;\n    }\n}\n```\n
[]