Dec 25, 2008

How to implement a stack that also supports min/max operation in O(1)

How to implement a stack that also supports min/max operation in O(1)

For each element in the stack, we set a structure like this (value, (max, min)), when we push the element, update the new coming element’s (max, min) pair based on the existing elements in stack. For popping the element, we can know the max and min of current stack

No comments:

Post a Comment