classSolution {publicint[] nextGreaterElements(int[] nums) {int[] result =newint[nums.length];// remember: Arrays.fill()Arrays.fill(result,-1);// store the index of num in numsDeque<Integer> stack =newLinkedList<>();// loop twicefor(int i=0; i<nums.length*2; i++){// get the mod of iint index = i%nums.length;while(stack.size()>0&& nums[stack.peek()]<nums[index]){ result[stack.pop()] = nums[index]; }stack.push(index); }return result; }}