1727. Largest Submatrix With Rearrangements Medium
1/**
2 * [1727] Largest Submatrix With Rearrangements
3 *
4 * 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.
5 * Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/12/29/screenshot-2020-12-30-at-40536-pm.png" style="width: 500px; height: 240px;" />
9 * Input: matrix = [[0,0,1],[1,1,1],[1,0,1]]
10 * Output: 4
11 * Explanation: You can rearrange the columns as shown above.
12 * The largest submatrix of 1s, in bold, has an area of 4.
13 *
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2020/12/29/screenshot-2020-12-30-at-40852-pm.png" style="width: 500px; height: 62px;" />
16 * Input: matrix = [[1,0,1,0,1]]
17 * Output: 3
18 * Explanation: You can rearrange the columns as shown above.
19 * The largest submatrix of 1s, in bold, has an area of 3.
20 *
21 * Example 3:
22 *
23 * Input: matrix = [[1,1,0],[1,0,1]]
24 * Output: 2
25 * 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.
26 *
27 *
28 * Constraints:
29 *
30 * m == matrix.length
31 * n == matrix[i].length
32 * 1 <= m * n <= 10^5
33 * matrix[i][j] is either 0 or 1.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/largest-submatrix-with-rearrangements/
39// discuss: https://leetcode.com/problems/largest-submatrix-with-rearrangements/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn largest_submatrix(matrix: Vec<Vec<i32>>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1727() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.