716. Max Stack

Design a stack that supports the following operations in O(1) time:

  • push(x): Push element x onto stack
  • pop(): Remove and return the top element
  • top(): Return the top element without removing it
  • peekMax(): Return the maximum element in the stack
  • popMax(): Remove and return the maximum element in the stack
Examples
Input: [["MaxStack","push","push","push","top","popMax","top","peekMax","pop","top"],[[],[5],[1],[5],[],[],[],[],[],[]]]
Output: [null,null,null,null,5,5,1,5,1,5]
Hints
Related Problems

716. Max Stack

Design a stack that supports the following operations in O(1) time: