Max Stack
This is in a few places as having a stack which keeps track of the min/max
Here we set up two stacks simultaneously in the MaxStack class. With some logic we only push to the MaxStack if the number is greater. Only pop if we are popping the top value of the MaxStack too.
I am always tempted to add properties to the class but it seems the solution rarely does this.
Also, remember if they give you an implementation of a class already then use it!
Top comments (0)