We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def checkR(number, index, h):
counter = 0
for element in range((index +1), len(h)):
if number <= h[element]:
counter+=1
else:
break
return counter
def checkL(number, index, h):
counter = 0
for element in reversed(range(index)):
if number <= h[element]:
counter+=1
else:
break
return counter
maxArea = 0
currentArea = 0
# Write your code here
for i in range(len(h)):
if (i==0):
R = checkR(h[i], i, h)
currentArea = (R+1)* h[i]
elif (i==(len(h)-1)):
L=checkL(h[i], i, h)
currentArea = (L+1)*h[i]
else:
L = checkL(h[i], i, h)
R = checkR(h[i], i, h)
currentArea = (L+R+1)*h[i]
maxArea = max(currentArea, maxArea)
return maxArea
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
def largestRectangle(h):