Next Greater Element II.
Asked in the Round 1 DSA stage.
Implement a function that returns, for each element in a circular integer array, the first greater element to its right. If no greater element exists, return -1 for that position.
next_greater_elements(nums)
nums: a list of integersresult[i] is the next greater element for nums[i] in circular order.Input: nums = [1, 2, 1]
Output: [2, -1, 2]
Input: nums = [3, 8, 4, 1, 2]
Output: [8, -1, 8, 2, 3]
def next_greater_elements(nums):