Using map (C++) but pretty Slow approach
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n    O(NlogN)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) \n  
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(NlogN)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        int n = nums.size();\n        \n        map<int,bool>num;\n        set<int>st;\n        unordered_map<int,vector<int>>ind;\n        for(int i = 0;i<n;i++){\n            int e = nums[i];\n            num[e] = true;\n            ind[e].push_back(i);\n            st.insert(i);\n        }\n\n        vector<int>ans(n,-1);\n        unordered_map<int,set<int>>fnal;\n        for(auto e:num){\n            for(auto in:ind[e.first]){\n                st.erase(in);\n            }\n            for(auto in:ind[e.first]){\n                 auto it1 = st.upper_bound(in);\n                if(it1 == st.end())continue;\n                auto it2 = st.upper_bound(*it1);\n                if(it2 == st.end())continue;\n                ans[in] = nums[*it2];\n            }\n        }\n\n        return ans;\n    }\n};\n```
['Ordered Map', 'C++']