Easy Solution ✅ || Explained || C++ || Stack
Code\n\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n=nums.size();\n        vector<int> ans(n,-1);\n       
# Code\n```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n=nums.size();\n        vector<int> ans(n,-1);\n        stack<int> s;\n        for(int i=2*n-1;i>=0;i--)\n        {\n            // we pop out all elements smaller than current element\n            while(!s.empty() && s.top()<=nums[i%n]){\n                s.pop();\n            }\n            // if stack is empty means no greater element is there\n            // if not empty we make answer at that index equal to top element\n            if(!s.empty() && i<n)\n            ans[i]=s.top();\n            s.push(nums[i%n]);\n        }\n        return ans;\n    }\n};\n```\n\n**Do Upvote \uD83D\uDC4D and Comment \uD83D\uDCAC**
['Stack', 'C++']