Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 279 Bytes

17298.md

File metadata and controls

18 lines (14 loc) · 279 Bytes

17298

Python

N = int(input())
lst = list(map(int, input().split()))
answer = [-1] * N
stack = []

stack.append(0)
for i in range(1, N):
    while stack and lst[stack[-1]] < lst[i]:
        answer[stack.pop()] = lst[i]
    stack.append(i)
    
print(*answer)