Given a circular array, find the next greater element for each position. The array wraps around, so after the last element comes the first.
With [1, 2, 1]:
- Position 0 (1): next greater is
2at position 1. - Position 1 (2): wrap around.
1, 1are both smaller. No next greater. Answer:-1. - Position 2 (1): wrap to position 0 (1, same). Then position 1 (2). Next greater is
2.
Result: [2, -1, 2].
Constraints: length .