Largest Submatrix With Rearrangements

You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.

Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.

Example 1
0 0 1
1 1 1
1 0 1
Inputmatrix = [[0,0,1],[1,1,1],[1,0,1]]
Output4
You can rearrange the columns so the largest submatrix of 1s has an area of 4.
Example 2
1 0 1 0 1
Inputmatrix = [[1,0,1,0,1]]
Output3
You can rearrange the columns so the largest submatrix of 1s has an area of 3.

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m * n <= 10^5
  • matrix[i][j] is either 0 or 1.

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate