Next Greater Element II - [C++]
\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> ans(n,-1),stack;\n     
```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> ans(n,-1),stack;\n        for(int i=0;i<2*n;i++){\n            while(stack.size() && nums[stack.back()] < nums[i%n]){\n                ans[stack.back()] = nums[i%n];\n                stack.pop_back();\n            }\n            stack.push_back(i%n);\n        }\n        return ans;\n    }\n};\n```\n\n![image](https://assets.leetcode.com/users/images/e748d137-70df-4590-9d6d-ee9dfa93c743_1687283533.4526136.jpeg)\n\nplease upvote! if you like.\nComment below \uD83D\uDC47
['Stack', 'C']