Python solution explained
\n\'\'\'\nThe idea here is to store the indexes of the elements that we haven\'t seen a greater than value for them yet\nwe do this because if you stored the va
```\n\'\'\'\nThe idea here is to store the indexes of the elements that we haven\'t seen a greater than value for them yet\nwe do this because if you stored the values you wouldn\'t be able to easily know where a value is at so you\ncan set it accordingly. This comes in handy in the second loop.\n\nThe values in the stack when we enter the second loop will always be decending, this is an important part of knowing that \nwe are setting the indexes to their correct value. Since we always will set the index\'s left in the stack to the smallest\nnumber when reiterating over the stack, ensuring a correct answer. \n\'\'\'\n\nclass Solution(object):\n    def nextGreaterElements(self, nums):\n        stack = []\n        result = [-1] * len(nums)\n        \n        for i in range(len(nums)):\n            while stack and nums[stack[-1]] < nums[i]:\n                result[stack.pop()] = nums[i]\n            stack.append(i)\n\n        for i in range(len(nums)):\n            while stack and nums[stack[-1]] < nums[i]:\n                result[stack.pop()] = nums[i]\n                \n        return result\n    \n\n```
[]