Using increasing stack , 95.21% efficient.
Intuition\n Describe your first thoughts on how to solve this problem. \nTo use stack as it works on lifo method and make it an increasing stack by appending an
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo use stack as it works on lifo method and make it an increasing stack by appending and popping so that the next greater element is the top of the stack.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse a stack and a result array, make sure that the stack is in increasing order and traverse the array given as it is circular can traverse in inverse manner, then check if the stack exist and if the top element is less than the visting element in the given array then pop out that element as we are trying to maintain the stack in increasing manner, to get result check if we are in nums and then if the stack exist add the top to the result else add the element to the stack.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N) as the while loop is not travers only the traversing the whole nums, only the element present in the stack.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# Code\n```\nclass Solution:\n    def nextGreaterElements(self, nums: List[int]) -> List[int]:\n        # Initializing the ans and stack \n        n = len(nums)\n        result = [-1] * n\n        st = []\n        # Traversing through the array by 2n-1 as we are using an imaginary \n        # array of size n and as the array is circular we can traverse in reversibly also\n        # It will not affect the ans\n        for i in range(2*n-1,-1,-1):\n            # Using while loop to remove the element which are less than the element \n            # we are traversing at in the stack\n            # using index as that because this is a circular array\n            while st and st[-1] <= nums[i%n]:\n                st.pop()\n            # When we are before the end of the nums if stack exist then add the \n            # top value of the stack to the result array as this will be the nge\n            if (i <n):\n                if st:\n                    result[i] = st[-1]\n            # else append the value in the stack as the stack is in increaing order\n            # no element is smaller than the visiting element in the stack\n            st.append(nums[i%n])\n        return result\n\n        \n```
['Python3']