Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def find(a):
- q=deque()
- n=len(a)
- pre,pos=[-1]*n,[n]*n
- for i,val in enumerate(a):
- while q and a[q[-1]]>=val:#top>=cur increasing stack
- idx=q.pop()
- pos[idx]=i
- if q:
- pre[i]=q[-1]
- q.append(i)#This I forget always Keep remember this
- print(pre,pos)
- find([1,4,3,7,4,5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement