Concise Java Solution
\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        Stack<Integer> stack = new Stack<>();\n        int [] result = new int[nums.leng
```\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        Stack<Integer> stack = new Stack<>();\n        int [] result = new int[nums.length];\n        int size = nums.length;\n        Arrays.fill(result,-1);\n        for(int i=2*size-1; i>=0; i--){\n            while(!stack.isEmpty() && nums[stack.peek()]<=nums[i%size])\n                stack.pop();\n        \n            if(stack.isEmpty()){\n                stack.push(i%size);\n            }else{\n                result[i%size]=nums[stack.peek()];\n                stack.push(i%size);\n            }\n        }\n     return result;\n    }\n}\n```
[]