MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / LRA

Method LRA

85-maximal-rectangle/maximal-rectangle.py:2–21  ·  view source on GitHub ↗
(self, heights: list[int])

Source from the content-addressed store, hash-verified

1class 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])

Callers 1

maximalRectangleMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected