C++||Stack
\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        stack<int>s;\n        vector<int>v;\n        int n = nums.size();
```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        stack<int>s;\n        vector<int>v;\n        int n = nums.size();\n        for(int i=n-2;i>=0;i--){\n            while(s.size()>0&&s.top()<=nums[i])s.pop();\n            s.push(nums[i]);\n        }\n        for(int i=n-1;i>=0;i--){\n            while(s.size()>0&&s.top()<=nums[i])s.pop();\n            v.push_back(s.size()==0?-1:s.top()); //if no greater element push -1.\n            s.push(nums[i]);\n            \n        }\n        reverse(v.begin(),v.end());\n        return v;\n    }\n};\n```
['Stack', 'C']