Advertisement
whiteshark05

Mono stack

Mar 27th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.21 KB | Software | 0 0
  1. A = [51, 49, 45, 30, 35, 50, 45, 46, 41, 49, 60]
  2. stack = []
  3. n = len(A)
  4. ans = 0
  5. for i in range(n):
  6.     while stack and A[stack[-1]] < A[i]:
  7.         ans = max(ans, i - stack.pop())
  8.     stack.append(i)
  9. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement