Monotonic stack + minHeap
IntuitionVery similar to https://leetcode.com/problems/next-greater-element-i/
with one additonal change.*Alternative to this approach is  to use one more "temp
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Very similar to https://leetcode.com/problems/next-greater-element-i/
with one additonal change.

*Alternative to this approach is  to use one more "temp" stack to help you keep the "order" of the value of elements.


# Approach
-Monotonic stack => The stack keeps the elements for which we are still looking for the *first* candidate that will be bigger than them.

If we encounter a new max in the for loop, bigger than the one we keep in stack we will pop the values from the stack and transfer them to the min heap priority queue.(as we found a first bigger element)

-Priority Queue(min heap) keeps the elements for which we are looking for the *second* candidate that will be bigger than them.
As asoon as we encounter this in the for loop, we can add the answer to the answer array.

**Why a min heap instead of a second stack?**

Imagine this case : [12,0,15,12]
=>We encounter 12, it's the first element, we push idx 0 in stack.
=>We encounter 0, minHeap is empty, ans this element is smaller than 12 so no pop, we add idx 1 to the stack.
=>[**first bigger element**]We enocunter 15. 15 will cause 12 and 0 to pop out of the stack. 

Imagine if we used **another** stack, the order would have been :
stack(keeps the idx-s) : bottom=1  0=top in the second stack
but for minHeap it would be 
minHeap bottom=0 1=top (because in the minheap the smallest value would be on top)
=>We ecnounter 12
^In the stack we would have gotten a **wrong** answer because on top of our hypothetical second stack it's 12 => so we would **not** have written the answer
^In the pq we will receive the correct answer because pq will have the smallest element first which will be idx 1 with value 0 which is less than 15

# Complexity
- Time complexity:
The loop is O(n), Every element is pushed and popped and most once.In the pq for each element we queue and dequeue at most once. Both queue and dequeue are logk operations, where k is the number of elements in the queue.
Worse case : nlogn


- Space complexity:
O(n), minHeap and stack will have at most n elements.

# Code
```csharp []
public class Solution {
    public int[] SecondGreaterElement(int[] nums) {
        
        return NextGreaterElement(nums);
    }

    public int[] NextGreaterElement(int[] nums)
    {
        int n = nums.Length;
        int[] ans = new int[n];
        Array.Fill(ans, -1);
        
        Stack<int> monoStack = new();
        PriorityQueue<int,int> pq = new(); //[12,0,15,12]
        int[] counter = new int[n];

        for(int i = 0; i  < n;i++ )
        {

            while(pq.TryPeek(out int idx, out int val) && val<nums[i])
            {
                pq.Dequeue();
                ans[idx] = nums[i];
            }
            //new max was found
            while(monoStack.Count!=0 && nums[monoStack.Peek()]<nums[i])
            {
                int topIdx = monoStack.Pop();
                pq.Enqueue(topIdx, nums[topIdx]);
            }

            monoStack.Push(i);
        }

        return ans;
    }
}
```
['Stack', 'Heap (Priority Queue)', 'Monotonic Stack', 'C#']