Google Interview Question

Write the Java code for a stack that implements pop(), push(), peek(), offer(), etc and gets the maximum value in constant time.

Interview Answer

Anonymous

Dec 9, 2012

Use LinkedList (this was an acceptable way) for most operations and have a separate LinkedList to keep track of the maximum element, adding the maximum at time of the insert to it.