stock = [1, 2, 3, 4, 5]
target = [4, 3, 5, 2, 1]
stack = []
index = 0
for book in stock:
stack.append(book)
while stack and stack[-1] == target[index]:
stack.pop()
index += 1
if index == len(target):
print("Possible")
else:
print("Impossible")
To embed this project on your website, copy the following code and paste it into your website's HTML: