Simple approach using stack || O(N) time ||
\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        //idea is to go for next gtreater in nums+nums\n     
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        //idea is to go for next gtreater in nums+nums\n        int n=nums.size();\n        nums.resize(2*n);\n        for(int i=n;i<2*n;i++){\n            nums[i]=nums[i-n];\n        }\n        vector<int>res(n);\n        stack<int>st;\n        for(int i=nums.size()-1;i>=0;i--){\n            while(!st.empty() && nums[i]>=nums[st.top()]){\n                st.pop();\n            }\n            int idx=i%n;\n            res[idx]=st.empty()?-1:nums[st.top()];\n            st.push(i);\n        }\n        return res;\n    }\n};\n```
['Stack', 'C++']