achieved it using the same next greater elements approach to selective part.
IntuitionIntuition is just the nge.Approachstore the elements whose next greater is current element at the current element index in form of a double vector kind
# Intuition
Intuition is just the nge.

# Approach
store the elements whose next greater is current element at the current element index in form of a double vector kind of structure. 

now this will help us in a way suppose that an index a has next greater at b, we stored a at b.

now when we apply the nge for next time the moment we arrive at b we check the stack not for b but for a because one greater is already at b, the second greater will be from a. now its like we shift the focus.

Hence the solution.


# Code
```cpp []
class Solution {
public:
    vector<int> secondGreaterElement(vector<int>& nums) {
        ios::sync_with_stdio(false);

        stack<int> st;

        vector<vector<int>> ans1 (nums.size());

        for(int i = nums.size()-1; i>-1 ; i--){
            while(!st.empty() && nums[st.top()] <= nums[i]){
                st.pop();
            }
            if(!st.empty()){
                ans1[st.top()].push_back(i);
            }

            st.push(i);
        }


        while(!st.empty()){
            st.pop();
        }

      

vector<int> ans(nums.size(),-1);

        for(int i = nums.size()-1; i> -1; i--){

                for(int it = 0; it < ans1[i].size() && !st.empty(); it++){

                    while(!st.empty() && nums[st.top()] <= nums[ans1[i][it]]){
                        st.pop();
                    }

                    if(!st.empty()){
                        ans[ans1[i][it]] = nums[st.top()];
                    }

                    

                }
            st.push(i);
                    }
                    return ans;
    }
};
```
['C++']