[Python] Simple 2 pass solution using stack, 99% faster
\nclass Solution:\n    def nextGreaterElements(self, nums: List[int]) -> List[int]:\n        ## RC ##\n        ## APPROACH : STACK ##\n        ## Similar to lee
```\nclass Solution:\n    def nextGreaterElements(self, nums: List[int]) -> List[int]:\n        ## RC ##\n        ## APPROACH : STACK ##\n        ## Similar to leetcode 739. Daily Temperatures ##\n        \n        ## LOGIC ##\n        ## 1. Monotone decreasing stack to find NGE (next greater element)\n        ## 2. In the first loop, we fill NGE all possible.\n        ## 3. In the second loop, there might be some elements left in the stack, so we iterate again (without appending to stack) and get NGE\n        ## 4. The elements that are left in the stack even after second loop are max(nums).\n        \n\t\t## TIME COMPLEXITY : O(N) ##\n\t\t## SPACE COMPLEXITY : O(N) ##\n\n        stack, res = [], [-1] * len(nums)\n        for i, num in enumerate(nums):              # 2\n            while stack and nums[stack[-1]] < num:\n                res[stack.pop()] = num\n            stack.append(i)\n        for i, num in enumerate(nums):              # 3\n            while stack and nums[stack[-1]] < num:\n                res[stack.pop()] = num\n        return res\n```
['Python', 'Python3']