Measure the Largest All-One Grid Rectangle

Quick Overview

Find the largest axis-aligned rectangle containing only one characters in a binary character grid, returning its cell area.

Measure the Largest All-One Grid Rectangle

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem The rectangular grid `bits` contains the characters `0` and `1`. Return the largest area of an axis-aligned rectangle made entirely of `1` cells. Such a rectangle consists of consecutive rows and consecutive columns. Its area is the number of cells it contains. Return `0` if there is no `1` cell. ### Examples **Example 1** ```text Input: bits = [["1","1","0"],["1","1","1"],["0","1","1"]] Output: 4 ``` A two-by-two block of `1` cells has area `4`; no larger all-`1` rectangle exists. **Example 2** ```text Input: bits = [["0","0","0"],["0","0","0"]] Output: 0 ``` No cell can belong to a positive-area all-`1` rectangle. ### Constraints - The grid has between `1` and `200` rows and between `1` and `200` columns. - All rows have the same length. - Every cell holds the character `0` or the character `1`.

Overview: Find the largest axis-aligned rectangle containing only one characters in a binary character grid, returning its cell area.

Amazon logo
Amazon
Oct 12, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The rectangular grid bits contains the characters 0 and 1. Return the largest area of an axis-aligned rectangle made entirely of 1 cells.

Such a rectangle consists of consecutive rows and consecutive columns. Its area is the number of cells it contains. Return 0 if there is no 1 cell.

Examples

Example 1

Input: bits = [["1","1","0"],["1","1","1"],["0","1","1"]]
Output: 4

A two-by-two block of 1 cells has area 4; no larger all-1 rectangle exists.

Example 2

Input: bits = [["0","0","0"],["0","0","0"]]
Output: 0

No cell can belong to a positive-area all-1 rectangle.

Constraints

  • The grid has between 1 and 200 rows and between 1 and 200 columns.
  • All rows have the same length.
  • Every cell holds the character 0 or the character 1 .