dsa · medium

Min Stack + Get Middle

GreyOrangeStackLinked ListDesign

GreyOrange live follow-up on min stack: 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.

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]

Open in the Dojo editor