What if you make a linked list, as you said, but also keep the current minimum value. When you add a new number, it looks at the previous min and changes the current min to the current value if the current value is lower.
For example ... Suppose you have data: 3, 6, 4, 2, 7, 1. Then it will look like
value | min
3 | 3 β 6 | 3 β 4 | 3 β 2 | 2 β 7 | 2 β 1 | 1
This will keep track of the minutes when adding / removing items.
EDIT: I mentioned going back, it would be something like this: 1 | 1 β 7 | 2 β 2 | 2 β 4 | 3 β 6 | 3 β 3 | 3 Then you do not need a footer.
source share