Python (Simple Heap)
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def secondGreaterElement(self, nums):\n        n = len(nums)\n\n        first, second, ans = [], [], [-1]*n\n\n        for i in range(n):\n            while second and nums[i] > second[0][0]:\n                val, idx = heapq.heappop(second)\n                ans[idx] = nums[i]\n\n            while first and nums[i] > nums[first[-1]]:\n                tmp = first.pop()\n                heapq.heappush(second,(nums[tmp],tmp))\n\n            first.append(i)\n        \n        return ans\n```
['Python3']