Next Greater Element II - Miscellaneous / Monotonic Stack

I think we can make the java solution bit simpler by not having a inner class

public static List nextGreaterElements(List nums) {
// we will loop the input twice as it is considered as circular
int n = nums.size();
int i = n * 2 - 1;

Integer[] result = new Integer[n];
// intial value -1; if we dont find next greater value then we leave -1 as it is;
Arrays.fill(result, -1);

// maintaining decreasing value only is deque
Deque deque = new ArrayDeque();

while (i >= 0) {
int currIndex = i % n;
while (!deque.isEmpty() && nums.get(currIndex) >= deque.getLast()) {
deque.removeLast();
}
if (!deque.isEmpty())
result[currIndex] = deque.getLast();
deque.addLast(nums.get(currIndex));
i–;
}

return List.of(result);
}