import sys
from sys import stdin, stdout
N = int(sys.stdin.readline())
lst = [int(x) for x in sys.stdin.readline().split()]
stack = [1]
train = 2
for i in range(N):
if len(stack) == 0:
break
if stack[-1] < lst[i]:
for j in range(train, lst[i]+1):
stack.append(j)
train += 1
elif stack[-1] > lst[i]:
sys.stdout.write("No")
sys.exit()
else:
stack.pop()
stack.pop()
sys.stdout.write("Yes")
#π Help
10 messages Β· Page 1 of 1 (latest)
@onyx jackal
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
i solved this question without using a stack but since i gotta use a stack here i am.. π
the code passes every test case except 1 so im assuming its an extreme one
i think it might have something to do with the stack.pop() at the end
damn i just fixed it how do i close this
Use this !close
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.