use a map...
traverse through the array, maintain a set of seen elements.\n2. for current element, we mark elements smaller than current. \n - if some element is already mar
1. traverse through the array, maintain a set of seen elements.\n2. for current element, we mark elements smaller than current. \n - if some element is already marked, then current is the second greater of it, we can remove it from the seen set.\n\ncannot tell the time complexity, maybe O(nlogn), but accepted\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        vector<int> ans(nums.size(), -1);\n        multimap<int, pair<int, int>> m;// key(element from nums), (the mark), (index of this element)\n        for (int i = 0; i < nums.size(); i++) {\n            int x = nums[i];\n            for (auto it = m.begin(); it != m.end();) { // \n                if (it->first >= x) break; // only mark element smaller than x (according to the problem description)\n                if (it->second.first == 1) { // already marked, this is the second time (means current element is the second greater of it, means job is done for it, we can remove it freely)\n                    ans[it->second.second] = x;\n                    it=m.erase(it);\n                } else { // first time mark\n                    it->second.first++;\n                    it++;\n                }\n            }\n            m.insert({ x,{0,i} });\n        }\n        return ans;\n    }\n};\n```
['C']