@invalid

f is a list that its index means position and f[i] means the day that flower i opens.

The stack is strictly decreasing, in terms of f[i]. When a new index j arrives, we know for every index x ( stack[-1] < x < j) f[x] > f[j] and f[x] > f[stack[-1]]. This means for every flower x, it opened after j and stack[-1]. So if there is k spots between j and stack[-1], this is a valid result.

How do we keep the stack strictly decreasing? Before appending the new index j, we pop every index x that f[x] > f[j].

It took me a while to understand. I hope this will help.