Description

Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

Examples

Input:matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
Output:6
Explanation:

Rows 2-3, cols 2-4 form a 2x3 rectangle of 1s. Area=6. Use histogram approach per row.

Input:matrix = [["0"]]
Output:0
Explanation:

Single cell is '0'. No rectangle of 1s exists; area = 0.

Input:matrix = [["1","1","1"],["1","1","1"],["1","1","1"]]
Output:9
Explanation:

Entire 3x3 matrix is 1s. Maximal rectangle = entire grid. Area = 3x3 = 9.

Constraints

  • 1 ≤ rows, cols ≤ 200
  • matrix[i][j] is '0' or '1'

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!