• + 0 comments

    def largestRectangle(h):

    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