C++ || Monotonic Stack || 503
\n vector<int> nextGreaterElements(vector<int>& nums) {\n        stack<int> ele;\n        vector<int> ans1;\n        int i,x;\n        int n=nums.size();\n     
```\n vector<int> nextGreaterElements(vector<int>& nums) {\n        stack<int> ele;\n        vector<int> ans1;\n        int i,x;\n        int n=nums.size();\n        for(i=0;i<n;i++)\n        {\n            int j=(i+1)%n;\n            while((j)%n!=i)\n            {\n               if(nums[j]>nums[i])\n               {\n                   \n                   ele.push(nums[j]);\n                   break;\n                }\n                j=(j+1)%n;\n             }\n            if(!ele.empty())\n            {\n                 x=ele.top();\n                 ele.pop();\n                 ans1.push_back(x);\n            }\n            else\n            {\n           ans1.push_back(-1);\n            }  \n        }\n    return ans1;\n       \n```
['Monotonic Stack']