Java solution using O(1) time for getMin() and O(1) space
\nclass MinStack {\n    \n    Stack<int[]> stack;\n\n    /** initialize your data structure here. */\n    public MinStack() {\n        stack = new Stack<int[]>(
```\nclass MinStack {\n    \n    Stack<int[]> stack;\n\n    /** initialize your data structure here. */\n    public MinStack() {\n        stack = new Stack<int[]>();\n        \n    }\n    \n    // method to push a new element along with the min value till that point\n    public void push(int x) {\n        // if the stack is empty push the element to stack, min=element itself\n\t\tif (stack.empty()) {\n\t\t\tstack.push(new int[] { x, x });\n\t\t\treturn;\n\t\t}\n\n\t\t// compare the top min element with the new element, if new element is\n\t\t// smaller\n\t\t// then add the new min as the current element\n\t\tint currentMin = stack.peek()[1];\n\t\tstack.push(new int[] { x, Math.min(currentMin, x) });\n        \n        \n    }\n    \n    public void pop() {\n        stack.pop();\n        \n    }\n    \n    public int top() {\n        return stack.peek()[0];\n        \n    }\n    \n    public int getMin() {\n        return stack.peek()[1];\n        \n    }\n    \n    public boolean isEmpty() {\n        return stack.empty();\n    }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack obj = new MinStack();\n * obj.push(x);\n * obj.pop();\n * int param_3 = obj.top();\n * int param_4 = obj.getMin();\n */\n```
[]