1727. Largest Submatrix With Rearrangements

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1727

class Solution:
    def largestSubmatrix(self, matrix: List[List[int]]) -> int:
        for i in range(1, len(matrix)):
            for j in range(len(matrix[0])):
                if matrix[i][j]:
                    matrix[i][j] = matrix[i - 1][j] + 1
        res = 0
        for row in matrix:
            row.sort(reverse=True)
            for j, v in enumerate(row, 1):
                res = max(res, j * v)
        return res