java | easy solution | stack | 100% faster
\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        \n        int n = nums.length;\n        int[] output = new int[n];\n        Stac
```\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        \n        int n = nums.length;\n        int[] output = new int[n];\n        Stack<Integer> st = new Stack<Integer>();\n        Arrays.fill(output , -1);\n        \n        for(int i = 0 ; i < 2*n ; i++){\n            int idx = i%n;\n            \n            while(!st.empty() && nums[idx] > nums[st.peek()]){\n                output[st.peek()] = nums[idx];\n                st.pop();\n            }\n            st.push(idx);  \n        }\n        return output;\n    }\n```
['Stack', 'Java']