class Solution:
    def nextGreaterElements(self, nums: List[int]) -> List[int]:
        # main idea: double nums by using mode
        # time O(N) space O(N)
        # step1: create stack, initialize res 
        st = []
        size = len(nums)
        res = [-1] * size
        # step2: make stack strickly decreasing 
        for i in range(2*size-1,-1,-1):
            # step2.1: when current number is no less than stack top, pop off stack until stack top bigger
            while st and st[-1] <= nums[i%size]:
                st.pop()
            # step2.2: save next bigger number in res 
            res[i%size] = st[-1] if st else -1
            # step2.3: push current number into stack 
            st.append(nums[i%size])
        return res