Next Greater Element (Circular)

Medium · Stack & Monotonic Stack · about 20 minutes

Asked at Amazon, Google, Bloomberg.

Given a circular integer array nums (the element after the last is the first), return for each element the next greater number found by traversing forward, wrapping around if needed, or -1 if none exists.

Related guides