Simple Java Solution
\nclass Solution {\n    \n    public int[] nextGreaterElements(int[] nums) {\n     \n        Stack<Integer> stack = new Stack<>();\n        \n        int[] resu
```\nclass Solution {\n    \n    public int[] nextGreaterElements(int[] nums) {\n     \n        Stack<Integer> stack = new Stack<>();\n        \n        int[] result = new int[nums.length];\n        \n        process(nums, result, stack, true);\n                \n        process(nums, result, stack, false);  \n        \n        while (!stack.isEmpty()) {\n            \n            result[stack.pop()] = -1;\n        }\n        \n        return result;\n    }\n    \n    private void process(int[] nums, int[] result, Stack<Integer> stack, boolean push) {\n        \n        for (int i = 0; i < nums.length; i++) {\n            \n           while (!stack.isEmpty() && nums[stack.peek()] < nums[i]) {\n                    \n                result[stack.pop()] = nums[i];\n            }\n                \n            if (push)\n            stack.push(i);\n        }\n    }\n}\n```
['Java']