| 1 | class Solution: |
| 2 | def LRA(self, heights: list[int]) -> int: |
| 3 | stack = [] |
| 4 | max_area = 0 |
| 5 | n = len(heights) |
| 6 | |
| 7 | for i in range(n): |
| 8 | while stack and heights[stack[-1]] > heights[i]: |
| 9 | elem = stack.pop() |
| 10 | nse = i |
| 11 | pse = stack[-1] if stack else -1 |
| 12 | max_area = max(max_area, heights[elem] * (nse - pse - 1)) |
| 13 | stack.append(i) |
| 14 | |
| 15 | while stack: |
| 16 | nse = n |
| 17 | elem = stack.pop() |
| 18 | pse = stack[-1] if stack else -1 |
| 19 | max_area = max(max_area, (nse - pse - 1) * heights[elem]) |
| 20 | |
| 21 | return max_area |
| 22 | def maximalRectangle(self, matrix: List[List[str]]) -> int: |
| 23 | n = len(matrix) |
| 24 | m = len(matrix[0]) |