3
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```\n#include <stack>\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n     stack<int> s;\n     vector<int> x(nums);\n     int h=nums.size();\n     s.push(-1);\n     for(int i=2*h-1;i>=0;i--){\n         while(!s.empty() && s.top()<=nums[i%h]){\n             s.pop();\n         }\n         if(s.empty()){s.push(-1);}\n         x[i%h]=s.top();\n         s.push(nums[i%h]);\n     }\n     return x;\n    }\n};\n```
['C++']