Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/3682161f4460e6814c076a73998a601a to your computer and use it in GitHub Desktop.
Save completejavascript/3682161f4460e6814c076a73998a601a to your computer and use it in GitHub Desktop.
MAX = 1005
stack = [0] * MAX
while(1):
n = int(raw_input())
if n == 0:
break
order = map(int, raw_input().split())
st_size = 0
check = 1
start = 1
for i in range(0, n):
while (st_size > 0 and stack[st_size - 1] == start):
st_size -= 1
start += 1
if order[i] == start :
start += 1
elif st_size > 0 and stack[st_size - 1] < order[i]:
check = 0
break
else:
stack[st_size] = order[i]
st_size += 1
if check == 1:
print "yes\n"
else:
print "no\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment