Check it..........
Comment it\'s time complexity...\n\nvector<int> nextGreaterElements(vector<int>& v) \n    {\n        vector<int>ans(n,-1);\n        int n=v.size();\n        \n 
Comment it\'s time complexity...\n```\nvector<int> nextGreaterElements(vector<int>& v) \n    {\n        vector<int>ans(n,-1);\n        int n=v.size();\n        \n        //Initialize stack \n        stack<int>s;\n        for(int i=n-1;i>=0;i--)\n        {\n            s.push(v[i]);\n        }\n        \n        \n        // next greater element \n        for(int i=n-1;i>=0;i--)\n        {\n                while((!(s.empty()))&&(s.top()<=v[i]))\n                    s.pop();\n                \n                if(s.empty())\n                {\n                    ans[i]=-1;\n                }\n                else\n                {\n                    ans[i]=s.top();\n                }\n            s.push(v[i]);\n        }\n        \n        return ans;\n    }\n```
['Stack']