Max retrieval in O(1) complexity using a stack.