All problems
0198HardArrayDynamic ProgrammingStackMatrixMonotonic Stack

Largest Flawless Panel

Tracked in this browser only
Write code

Trains the technique from

LeetCode 85Maximal Rectangle

This 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 scanner inspects a sheet of veneer cell by cell and hands you the reading as panel, a grid of one-character strings. panel[i][j] is "1" when that cell of the sheet is flawless and "0" when the scanner found a blemish there. Every row of the reading has the same length.

A cutting machine can punch out one axis-aligned block of cells: pick a run of consecutive rows and a run of consecutive columns, and the block is every cell where the two runs meet. The block is sellable only if every cell inside it is flawless.

Return the number of cells in the biggest sellable block. If the sheet has no flawless cell at all, return 0.

Examples

Example 1

Input
panel = [["0", "1", "1", "0"], ["1", "1", "1", "1"], ["1", "1", "1", "1"], ["0", "1", "1", "0"]]
Output
8

Columns 1 and 2 are flawless down all four rows, giving a 4-by-2 block of 8 cells. The two middle rows offer a 2-by-4 block, also 8, and nothing larger exists because the corners are blemished.

Example 2

Input
panel = [["1", "1", "1"], ["1", "1", "1"]]
Output
6

Nothing is blemished, so the machine punches out the whole sheet.

Example 3

Input
panel = [["0", "0"], ["0", "0"]]
Output
0

Every cell carries a blemish, so no block can be sold.

Constraints

  • rows == panel.length
  • cols == panel[i].length
  • 1 <= rows, cols <= 200
  • panel[i][j] is "0" or "1"

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def largest_flawless_panel(panel: list[list[str]]) -> int:
Java
public int largestFlawlessPanel(char[][] panel)
September 7
Apply