using the stack || Array
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] secondGreaterElement(int[] A) {\n        int n = A.length,  res[] = new int[n];\n        Arrays.fill(res, -1);\n        Stack<Integer> s1 = new Stack<>(), s2 = new Stack<>(), tmp = new Stack<>();\n        for (int i=0; i < n; i++) {\n            while (!s2.empty() && A[s2.peek()] < A[i])\n                res[s2.pop()] = A[i];\n            while (!s1.empty() && A[s1.peek()] < A[i])\n                tmp.push(s1.pop());\n            while (!tmp.empty())\n                s2.push(tmp.pop());\n            s1.push(i);\n        }\n        return res;\n    }\n}\n```
['Java']