Using Stack in java
\n# Code\n\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n     Stack<Integer> st = new Stack<Integer>();\n    int v[]= new int[nums.leng
\n# Code\n```\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n     Stack<Integer> st = new Stack<Integer>();\n    int v[]= new int[nums.length];\n    for(int i=nums.length-1;i>=0;i--)\n          st.push(nums[i]);\n\n       for(int i= nums.length-1 ;i>=0;i--)\n       {\n           while(!st.isEmpty() && st.peek()<=nums[i])\n        {\n                st.pop();\n        }\n        if(st.isEmpty())\n            v[i]=-1;\n        else\n            v[i]=st.peek();\n        \n        st.push(nums[i]);\n        }\n        return(v);\n    }\n}\n```
['Java']