2454. Next Greater Element IV
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def secondGreaterElement(self, A: List[int]) -> List[int]:
        result_array, first_stack, second_stack = [-1] * len(A), [], []
        for current_index, current_value in enumerate(A):
            while second_stack and A[second_stack[-1]] < current_value:
                result_array[second_stack.pop()] = current_value
            temp_storage = []
            while first_stack and A[first_stack[-1]] < current_value:
                temp_storage.append(first_stack.pop())
            second_stack.extend(temp_storage[::-1])
            first_stack.append(current_index)
        return result_array

```
['Python3']