Trains the technique from
LeetCode 1727Largest Submatrix With RearrangementsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A punch card sheet is a grid of 0s and 1s given as matrix. The columns may be reordered freely, as often as you like, and reordering moves a whole column with all its entries.
A block is a rectangle of cells, taken from consecutive rows and consecutive columns of the reordered sheet, in which every cell is 1. Return the largest area a block can have, where area is the number of cells.
Example 1
The first column holds ones all the way down, giving a block one column wide and four rows tall, an area of 4.
Example 2
No two cells of ones share a row or a column band, so the largest block is a single cell.
Example 3
The single row is all ones, so the whole sheet is one block of area 4.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def widest_block(matrix: list[list[int]]) -> int:public int widestBlock(int[][] matrix)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.