Skip to content

Instantly share code, notes, and snippets.

@arpi-r
Created January 21, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arpi-r/6f78386db9d6ed1a3f10877dab23a172 to your computer and use it in GitHub Desktop.
Save arpi-r/6f78386db9d6ed1a3f10877dab23a172 to your computer and use it in GitHub Desktop.
codebuddy week10
class Solution:
# @param A : list of list of integers
# @return an integer
def histarea(self,h):
s = list()
maxarea = 0
i= 0
area = 0
while i < len(h):
if (not s) or (h[s[-1]] <= h[i]):
s.append(i)
i += 1
else:
top = s.pop()
area = (h[top] * ((i - s[-1] - 1) if s else i))
maxarea = max(maxarea, area)
while s:
top = s.pop()
area = (h[top] * ((i - s[-1] - 1) if s else i))
maxarea = max(maxarea, area)
return maxarea
def maximalRectangle(self, A):
l = A[0]
area = self.histarea(l)
maxarea = area
for i in range(1,len(A)):
for j in range(len(A[i])):
if A[i][j] == 1:
l[j] = l[j] + 1
else:
l[j] = 0
area = self.histarea(l)
if area > maxarea:
maxarea = area
return maxarea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment