Python stack solution


#1
def nextGreater(self, A):
    stack = []
    B = [-1] * len(A)
    for i, a in enumerate(A):
        while stack and stack[-1][0] < a:
            B[stack.pop()[1]] = a
        stack.append((a, i))
    return B