Solved LeetCode program · 85 of 1,000
#0085 · Maximal Rectangle
Original English source
The matrix is a list of 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, and 0. The rows is 4. The columns is 5. The width is columns plus 1. The height is rows plus 1. The size is width times height. The prefix is a list of size zeros.
For every row from 1 to rows.
For every column from 1 to columns.
The index is row times width plus column. The cellrow is row minus 1. The cellindex is cellrow times columns plus column minus 1. Set item index of prefix to item (index minus width) of prefix plus item (index minus 1) of prefix minus item (index minus width minus 1) of prefix plus item cellindex of matrix.
The best is 0.
For every top from 0 to one less than rows.
For every bottom from top to one less than rows.
For every left from 0 to one less than columns.
For every right from left to one less than columns.
The area is (bottom minus top plus 1) times (right minus left plus 1). The ones is item ((bottom plus 1) times width plus right plus 1) of prefix minus item (top times width plus right plus 1) of prefix minus item ((bottom plus 1) times width plus left) of prefix plus item (top times width plus left) of prefix. If ones is area and area is more than best, set best to area.
Display best.
Expected stdout
6