The meaning of the question Given a set of numbers, find the position of the largest number in the left (and right) consecutively smaller numbers of each number.
Ideas Let’s first consider how to find the position of the largest number among the consecutively smaller numbers on its left side. This uses a simple data structure-monotonic stack. Monotonic stack: monotonic stack is actually a stack, but it uses some Clever logic makes the elements in the stack remain in order (monotonically increasing or monotonically decreasing) every time a new element is pushed onto the stack. Here we are going to use a monotonically decreasing stack (that is, the subscript from the bottom of the stack to the top of the stack is increasing) Yes, but the data is decreasing) By the way, the stack is monotonically increasing (the subscript is increasing from the bottom of the stack to the top of the stack, but the data is also increasing). In terms of principle, after reading the code, you can taste your product~