Java easy Solution beats 94% submission 6 ms
\n    class Solution {\n        public int[] nextGreaterElements(int[] a) {\n\n\n            // List<Integer> l=new ArrayList<>();\n\n            int n=a.length
```\n    class Solution {\n        public int[] nextGreaterElements(int[] a) {\n\n\n            // List<Integer> l=new ArrayList<>();\n\n            int n=a.length;     \n            int max=a[0];\n            int cur=0;\n            for(int i=0;i<n;i++)\n            {\n            if(max<a[i])\n            {\n                max=a[i];\n                cur=i;\n            }\n                }\n                    int []res= new int[a.length];\n                    Stack<Integer> s=new Stack<>();\n                    s.push(a[cur]);\n                    res[cur]=-1;\n                    for(int i=cur-1;i>=0;i--)\n                    {\n                        while(s.size()>0 && a[i]>=s.peek())\n                        {\n                            s.pop();\n                        }\n                        if(s.size()>0)\n                        {\n                            res[i]=s.peek();\n                        }\n                        else\n                        {\n                            res[i]=-1;\n                        }\n                        s.push(a[i]);\n                    }\n\n\n\n                    for(int i=n-1;i>cur;i--)\n                    {\n                        while(s.size()>0 && a[i]>=s.peek())\n                        {\n                            s.pop();\n                        }\n                        if(s.size()>0)\n                        {\n                            res[i]=s.peek();\n                        }\n                        else\n                        {\n                            res[i]=-1;\n                        }\n                        s.push(a[i]);\n                    }\n\n         return res;\n            }\n        }\n\n\n```
[]