C++ most easiest solution and easy to understand
```\nclass Solution {\npublic:\n    vector nextGreaterElements(vector& nums) {\n        int n=nums.size();\n        vectorans(n,0);\n        stacks;\n        fo
```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n=nums.size();\n        vector<int>ans(n,0);\n        stack<int>s;\n        for(int i=n-1;i>=0;i--) {\n            s.push(nums[i]);\n        }\n        \n        for(int i=n-1;i>=0;i--) {\n            while(!s.empty() && nums[i]>=s.top()) s.pop();\n            if(s.empty()) ans[i]=-1;\n            else ans[i]=s.top();\n            s.push(nums[i]);\n        }\n        return ans;\n    }\n};\n
['Stack', 'C']