Runtime beats 96.41% [EXPLAINED]
IntuitionFind two numbers greater than each element in the array: the "first greater" and the "second greater," both appearing after the current index. Using st
# Intuition
Find two numbers greater than each element in the array: the "first greater" and the "second greater," both appearing after the current index. Using stacks helps us track these efficiently as we move through the array from left to right.

# Approach
Use three stacks to track indices of elements for the "first greater" and "second greater" comparisons as we iterate once through the array, updating results when conditions are met.

# Complexity
- Time complexity:
O(n): Each element is pushed and popped from the stacks at most once.

- Space complexity:
O(n): Stacks and result array store indices for up to all elements.

# Code
```python3 []
class Solution:
    def secondGreaterElement(self, nums):
        n = len(nums)
        result = [-1] * n
        first_stack, second_stack, temp_stack = [], [], []
        
        for i in range(n):
            while second_stack and nums[second_stack[-1]] < nums[i]:
                result[second_stack.pop()] = nums[i]
            
            while first_stack and nums[first_stack[-1]] < nums[i]:
                temp_stack.append(first_stack.pop())
            
            while temp_stack:
                second_stack.append(temp_stack.pop())
            
            first_stack.append(i)
        
        return result

```
['Array', 'Binary Search', 'Stack', 'Sorting', 'Heap (Priority Queue)', 'Monotonic Stack', 'Python3']