Class Solution
-
- All Implemented Interfaces:
public final class Solution1727 - Largest Submatrix With Rearrangements.
Medium
You are given a binary matrix
matrixof sizem x n, and you are allowed to rearrange the columns of thematrixin any order.Return the area of the largest submatrix within
matrixwhere every element of the submatrix is1after reordering the columns optimally.Example 1:
Input: matrix = [0,0,1,1,1,1,1,0,1]
Output: 4
Explanation: You can rearrange the columns as shown above. The largest submatrix of 1s, in bold, has an area of 4.
Example 2:
Input: matrix = [1,0,1,0,1]
Output: 3
Explanation: You can rearrange the columns as shown above. The largest submatrix of 1s, in bold, has an area of 3.
Example 3:
Input: matrix = [1,1,0,1,0,1]
Output: 2
Explanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.
Constraints:
m == matrix.lengthn == matrix[i].length<code>1 <= m * n <= 10<sup>5</sup></code>
matrix[i][j]is either0or1.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerlargestSubmatrix(Array<IntArray> matrix)-
-
Method Detail
-
largestSubmatrix
final Integer largestSubmatrix(Array<IntArray> matrix)
-
-
-
-