Very Easy Python Solution (Iterate first from left then from right)


#1
def distribute(self, A):
    n = len(A)
    output = [1]*n
    for i in range(n-1):
        if A[i+1] > A[i]:
            output[i+1] = output[i] + 1
    for i in range(n-1,0,-1):
        if A[i-1] > A[i] and output[i-1] <= output[i]:
            output[i-1] = output[i] + 1
    return sum(output)