[Python3] Monotonic Stack O(n)
We use two stacks stack and second to store the indices i  such that stack[i] and second[i] are non-increasing sequences. second stores the indices that already
We use two stacks ```stack``` and ```second``` to store the indices ```i```  such that ```stack[i]``` and ```second[i]``` are non-increasing sequences. ```second``` stores the indices that already meet the first greater element. We need a ```temp``` in the loop of ```stack``` so that the indices in ```second``` are increasing. \n```\nclass Solution:\n    def secondGreaterElement(self, nums: List[int]) -> List[int]:\n        n = len(nums)\n        output = [-1] * n\n        stack = []\n        second = []\n        for i in range(n):\n            while second and nums[i] > nums[second[-1]]:\n                curr = second.pop()\n                if output[curr] == -1:\n                    output[curr] = nums[i]\n            temp = []\n            while stack and nums[i] > nums[stack[-1]]:\n                curr = stack.pop()\n                if output[curr] == -1:\n                    temp.append(curr)\n            stack.append(i)\n            second += temp[::-1]\n        return output\n```
['Monotonic Stack', 'Python']