Python | Simple and straightforward | Combinations | Explained
\nfrom itertools import combinations\nclass Solution:\n    def maximumRows(self, mat: List[List[int]], cols: int) -> int:\n        rows = 0\n        \n        #
```\nfrom itertools import combinations\nclass Solution:\n    def maximumRows(self, mat: List[List[int]], cols: int) -> int:\n        rows = 0\n        \n        # iterate over each combintion of the given numer of columns\n        # the first argument passed to combinations is the list of columns\' indices\n        # the second argumnet is the number of columns we need to consider\n        # e.g., if mat consists of 3 columns, we\'ll iterate over the following list [(0,1), (0,2), (1,2)]\n        for c in combinations(range(len(mat[0])), cols):\n            \n            # initialise temp which is the number of valid rows for the current iteration\n            temp = 0\n            \n            # iterate over each row in mat\n            for r in mat:\n                valid = True\n                \n                # iterate over each number in the row (we use enumerate; the index of the number is the column\'s index)\n                # check if each number 1 present in the row is also present among columns we consider in the current most outer iteration (c)\n                # if that\'s not the case, the row is not valid\n                for col, n in enumerate(r):\n                    if valid and n == 1 and col not in c:\n                        valid = False\n                if valid:\n                    temp += 1\n            \n            # at the end of the current most outer iteration (c), check if the current number of valid rows (temp) is bigger then the previous one\n            rows = max(rows, temp)\n        return rows\n```\n
['Python', 'Python3']