Java Solution || Easy to Understand
\npublic class Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        int[] result = new int[nums.length];\n        Stack<Integer> stack = new 
```\npublic class Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        int[] result = new int[nums.length];\n        Stack<Integer> stack = new Stack<Integer>();\n        for (int i = 0; i < result.length; i ++) {\n            result[i] = -1;\n        }\n        for (int i = 0; i < 2 * result.length; i ++) {\n            int num = nums[i % result.length];\n            while (!stack.isEmpty() && nums[stack.peek()] < num) {\n                result[stack.pop()] = num;\n            }\n            if (i < result.length) {\n                stack.push(i);\n            }\n        }\n        return result;\n    }\n}\n```
['Java']