USING O(n) EXTRA SPACE WITHIN TIME O(n) SIMPLE AND EASY TO UNDERSTAND C++ SOLUTION
\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int i = 0, n = nums.size();\n        int k = n;\n        for(i = 
```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int i = 0, n = nums.size();\n        int k = n;\n        for(i = 0; i < n-1; i++){\n            nums.push_back(nums[i]);\n        }\n        stack<int> s;\n        n = nums.size();\n        vector<int> ans(n,-1);\n        for(i = n-1; i >= 0; i--){\n            while(!s.empty() && s.top()<=nums[i]){\n                s.pop();\n            }\n            if(!s.empty()){\n                ans[i] = s.top();\n            }\n            s.push(nums[i]);\n        }\n        return vector(ans.begin(),ans.begin()+k);\n    }\n};\n```
['Stack', 'C', 'Monotonic Stack', 'C++']