c++ | Simple | Single loop | stack
Simple solution with TC: O(2*n) , just using single loop.\n\n\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int 
Simple solution with TC: O(2*n) , just using single loop.\n\n```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n = nums.size();\n        vector<int>res(n,-1);\n        stack<int>s;\n        \n\t\t//in worst case we have to traverse array 2n times\n        for(int i=0;i<n*2;i++){\n\t\t    // if we reach end just change the index to 0\n            int ind = (i>=n)?i-n:i;\n            while(!s.empty() && nums[s.top()]<nums[ind]){\n                res[s.top()] = nums[ind];\n                s.pop();\n            }\n            s.push(ind); \n        }\n        return res;\n    }\n};\n```\n\nif found helpful please upvote!!!
['Stack', 'C']