Easy and short solution in python


#1
class Solution:
def prevSmaller(self, A):
    G = []
    for i in range(len(A)):
        while(len(G) > 0 and G[-1] >= A[i]):
            G.pop()
        x = G[-1] if len(G) > 0 else -1
        G.append(A[i])
        A[i] = x
    return A