Using Stack, Simple & Concise, [C++]
Implementation\n\nUsing Stack\nTime Complexity = O(2N), Space Complexity = O(N)\n\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& n
Implementation\n\n**Using Stack\nTime Complexity = O(2N), Space Complexity = O(N)**\n```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n = nums.size();\n        stack<int> s;        \n        vector<int> res(n, -1);\n        for(int itr = 2*n-1; itr >= 0; itr--){\n            while(!s.empty() && s.top() <= nums[itr%n]) s.pop();\n            if(!s.empty()) res[itr%n] = s.top();\n            s.push(nums[itr%n]);\n        }\n        return res;\n    }\n};\n```\nIf you find any issue in understanding the solution then comment below, will try to help you.\nIf you found my solution useful.\nSo **please do upvote and encourage me** to document all leetcode problems\uD83D\uDE03\nHappy Coding **:)**
['Stack', 'C']