[Python 3] O(n) Clean two stacks with comments
\nclass Solution:\n  def secondGreaterElement(self, nums: List[int]) -> List[int]:\n    ans = [-1] * len(nums)\n    # Decreasing stack that stores indices that 
```\nclass Solution:\n  def secondGreaterElement(self, nums: List[int]) -> List[int]:\n    ans = [-1] * len(nums)\n    # Decreasing stack that stores indices that already met the first greater num.\n    prevStack = []\n    # Decreasing stack that stores indices.\n    currStack = []\n\n    for i, num in enumerate(nums):\n      # Indices in prevStack meet second greater num.\n      while prevStack and nums[prevStack[-1]] < num:\n        ans[prevStack.pop()] = num\n      # Push indices that meet the first greater num from currStack to prevStack.\n      # We need a temp array to make indices in prevStack increasing.\n      decreasingIndices = []\n      while currStack and nums[currStack[-1]] < num:\n        decreasingIndices.append(currStack.pop())\n      for index in reversed(decreasingIndices):\n        prevStack.append(index)\n      currStack.append(i)\n\n    return ans\n```\n\nSince each num is pushed/popped from `prevStack`, `currStack`, and `decreasingIndices` at most once, the time complexity is O(n).\n\nTime: `O(n)`\nSpace: `O(n)`\n
['Stack', 'Python']