LC: 716. Max Stack - spiralgo/algorithms GitHub Wiki
716. Max Stack:
The Essence:
The aim of the question is to teach us how to design a Stack class with some extra methods like peekMax(), and popMax().
So, the problem solver should learn how to create a class in the programming language of choice first, then investigate the default Stack implementation to understand its behavior.
Details:
- Each time an element is pushed into the Stack, we can keep track of the maximum element in an extra Stack.
- Or we can find an efficient search method to find the maximum element each time when
peekMax(), orpopMax()is called. For the second option, the problem solver can have a look for the Linked List implementation for detailed information: https://github.com/spiralgo/algorithms/blob/900f3abbce98e3be3fd74545a6261cf4546c044d/src/main/java/algorithms/curated170/easy/maxstack/MaxStackLinkedList.java