Maximal Rectangle
You are given a grid made only of 0 and 1. Find the largest rectangle that contains only 1s and return its area (the number of cells). If the grid has no 1, return 0.
The rectangle must be axis-aligned: it covers a block of consecutive rows and consecutive columns.
Constraints
1 <= rows, columns <= 200- Every cell is
0or1.
Examples
Example 1
Input: matrix = [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]] Output: 6
The best rectangle is the 2 x 3 block of 1s in rows 1 and 2, columns 2 to 4: area 6.
Example 2
Input: matrix = [[0]] Output: 0
No 1s at all means area 0.
Example 3
Input: matrix = [[1]] Output: 1
A single 1 is a rectangle of area 1.
JavaScript you'll use: Arrays: create, read, update Stacks, queues and deques
/**
* @param {number[][]} matrix
* @return {number}
*/
function maximalRectangle(matrix) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.