Given a rows × cols binary matrix filled with '0's and '1's, find the largest rectangle containing only '1's and return its area.
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]6matrix = [["0"]]0matrix = [["1"]]1heights[0..n-1] = 0, maxArea = 0heights[c] += 1 if cell is '1', else reset to 0heights[] using monotonic stacki: area = heights[i] × width; update maxAreamaxArea after all rowsFor each row, heights[c] counts how many consecutive '1's end at that cell going upward. This transforms each row into a histogram problem (LC 84). The largest rectangle in that histogram is the biggest all-'1' rectangle whose bottom edge sits on that row. Running this for every row and taking the maximum gives the global answer in O(m × n).