JS - Very simple idea
\n//solves in O(1) time & O(n) extra space \nvar MinStack = function() {\n    this.arr = [];\n    //keeps track of min element at every point in lifetime of sta
```\n//solves in O(1) time & O(n) extra space \nvar MinStack = function() {\n    this.arr = [];\n    //keeps track of min element at every point in lifetime of stack \n    this.min = [];\n};\n\n/** \n * @param {number} x\n * @return {void}\n */\nMinStack.prototype.push = function(x) {\n    this.arr.push(x);\n    //if stack is empty\n    if(this.min.length === 0) this.min.push(x);\n    else {\n        //if stack is non empty push the min element between current ele and top of this.min\n        //for instance our stack was [-1, -0, -3]\n        //push(-1) this.arr = [-1] | this.min = [-1]\n        //push(0) this.arr = [-1, 0] | this.min = [-1, -1]\n        //push(-3) this.arr = [-1,0,-3] | this.min = [-1,-1,-3]\n        this.min.push(Math.min(this.min[this.min.length - 1], x));\n    }\n};\n\n/**\n * @return {void}\n */\nMinStack.prototype.pop = function() {\n    if(this.arr.length != 0) {\n        //pop ele from both this.arr and this.min\n        this.arr.pop();\n        this.min.pop();\n    }\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.top = function() {\n    //if this.arr non empty return element at last index of this.arr\n    if(this.arr.length != 0) return this.arr[this.arr.length -1];\n    return null\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.getMin = function() {\n    //if this.min non empty return element at last index of this.min\n    if(this.min.length != 0) return this.min[this.min.length -1];\n    return null\n};\n```\n
['JavaScript']