Easy solution
\n# Code\n\nclass Solution {\n    public int[] secondGreaterElement(int[] nums) {\n        int[] ans = new int[nums.length];\n        Arrays.fill(ans, -1);\n   
\n# Code\n```\nclass Solution {\n    public int[] secondGreaterElement(int[] nums) {\n        int[] ans = new int[nums.length];\n        Arrays.fill(ans, -1);\n        LinkedList<Integer> s1 = new LinkedList<>();\n        LinkedList<Integer> s2 = new LinkedList<>();\n        for (int i=0; i < nums.length; i++) {\n            while(!s2.isEmpty() && nums[i] > nums[s2.getLast()]) {\n                ans[s2.removeLast()] = nums[i];\n            }\n            LinkedList temp = new LinkedList<>();\n            while(!s1.isEmpty() && nums[i] > nums[s1.getLast()]) {\n                temp.addFirst(s1.removeLast());\n            }\n            s2.addAll(temp);\n            s1.addLast(i);\n        }\n        return ans;\n    }\n}\n```
['Java']