SHyeonL / Future_Internet_LAB_Algorithm

미래 인터넷 연구실 알고리즘 스터디
0 stars 0 forks source link

17298 - 오큰수 #14

Open yuneojin opened 1 year ago

yuneojin commented 1 year ago
import sys
input = sys.stdin.readline

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

stack.append(0)
for i in range(1, len(A)):
    while stack and A[stack[-1]] < A[i]:
        NGE[stack.pop()] = A[i]
    stack.append(i)

print(*NGE)