def nextGreatest(arr):
size = len(arr)
max_from_right = arr[size-1]
arr[size-1] = -1
for i in range(size-2,-1,-1):
temp = arr[i]
arr[i]=max_from_right
if max_from_right< temp:
max_from_right= temp

def printArray(arr):
for i in range(0,len(arr)):
print arr[i]

4d88b7a1157adf720106f807be3d824df6631037
def nextGreatest(arr):
size = len(arr)
max_from_right = arr[size-1]
arr[size-1] = -1
for i in range(size-2,-1,-1):
temp = arr[i]
arr[i]=max_from_right
if max_from_right< temp:
max_from_right= temp

def printArray(arr):
for i in range(0,len(arr)):
print arr[i]
