class Solution:
    def nextGreaterElements(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        st = []
        length = len(nums)
        res = [-1] * length
        
        for i in range(length * 2):
            num = nums[i % length]
            while(len(st) != 0 and nums[st[-1]] < num):
                res[st[-1]] = num
                st.pop(-1)
            if(i < length):
                st.append(i)
        
        
        return res
                
b30f93f0f914f4c51e22dc2a20988f7f78071f07
<mask token>

class Solution:
    <mask token>

class Solution:

    def nextGreaterElements(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        st = []
        length = len(nums)
        res = [-1] * length
        for i in range(length * 2):
            num = nums[i % length]
            while len(st) != 0 and nums[st[-1]] < num:
                res[st[-1]] = num
                st.pop(-1)
            if i < length:
                st.append(i)
        return res

class Solution:
    def nextGreaterElements(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        st = []
        length = len(nums)
        res = [-1] * length
        
        for i in range(length * 2):
            num = nums[i % length]
            while(len(st) != 0 and nums[st[-1]] < num):
                res[st[-1]] = num
                st.pop(-1)
            if(i < length):
                st.append(i)
        
        
        return res
                