Untitled
unknown
plain_text
a year ago
820 B
5
Indexable
from collections import deque
class Solution:
# @param A : list of integers
# @return a list of integers
def solve(self, A):
n = len(A)
st = deque()
temp_stack= deque()
for i in range(len(A)):
# st_A.append(A[i])
# while st_A:
# temp = st_A.pop() # Get current element
# temp_stack = deque() # To store elements temporarily
if len(st)>0:
while st and st[-1] > A[i]:
temp_stack.append(st.pop())
st.append(A[i])
while temp_stack: # Move back elements
st.append(temp_stack.pop())
arr = []
while len(st)>0:
arr.append(st.pop())
arr.reverse()
return arr
Editor is loading...
Leave a Comment