Simple || O(n)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        vector<int> sg(nums.size(), -1);\n        stack<int> s, t, u;\n        for(int i = 0;i < nums.size();i++) {\n            while(!u.empty() && nums[u.top()] < nums[i]) {\n                sg[u.top()] = nums[i];\n                u.pop();\n            }\n            while(!s.empty() && nums[s.top()] < nums[i]) {\n                t.push(s.top());\n                s.pop();\n            }\n            while(!t.empty()) {\n                u.push(t.top());\n                t.pop();\n            }\n            s.push(i);\n        }\n        return(sg);\n    }\n};\n```
['C++']