dsa · medium
Min Stack + Get Middle
push, pop, top, getMin, **getMiddle** all O(1) extra to the min. Middle is the lower-middle: index (n-1)//2 from the bottom (0-based). Empty never queried.
**Example:** push 1,2,3 → middle 2; pop → middle 1; getMin → 1.
Methods
MidStack()construct the structurepush(value)push onto the structuregetMiddle()the middle value currently in the stackgetMin()the smallest value still in the structure, in O(1)pop()remove the top/front as the statement defines (not called on empty unless noted)top()the top value, without removing it
Fill in the MidStack class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.
Example
`` MidStack() → null push(1) → null push(2) → null push(3) → null getMiddle() → 2 getMin() → 1 pop() → null getMiddle() → 1 top() → 2 ``
Constraints
Calls <= 1000
Examples
Example 1
Input: ["MidStack","push","push","push","getMiddle","getMin","pop","getMiddle","top"] [[],[1],[2],[3],[],[],[],[],[]] Expected: [null,null,null,null,2,1,null,1,2]