stack
to store pairs [price, span]
in a monotonically decreasing order.next(price)
, do the following:
span
to 1 (the current day).price
, pop the top element from the stack and add its span to the current span
.[price, span]
onto the stack.span
.