Simple C++|O(1)| 2 Liner| STL
Intuition\n Describe your first thoughts on how to solve this problem. \nWe either have to  use some other stack to keep track of  minimum till each index or we
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe either have to  use some other stack to keep track of  minimum till each index or we can have a stack pair. So actually what we will do is for each incoming element we will compare it with previous minimum element if it smaller then update the min else keep our min as it is.Also when stack is empty then we just have to push only..\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSo create a `stack<pair<int,int>>` and then in push function we can compare the incoming val that is to be pushed with the minimum till now and update accordingly and also check if stack is empty or not .\nAnd rest all other fucntions are same and in getmin() function just return top.second beacuse minimum of every index is stored in its second.\n# Complexity\n- Time complexity:O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass MinStack {\npublic:\n    stack<pair<int,int>>st;\n    MinStack() {\n    }\n    \n    void push(int val) {\n        if(!st.empty()){\n             int mini=min(st.top().second,val);\n             st.push({val,mini});\n        }\n        else st.push({val,val});\n    }\n    \n    void pop() {\n        st.pop();\n    }\n    \n    int top() {\n        return st.top().first;\n    }\n    \n    int getMin() {\n        return st.top().second;\n    }\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack* obj = new MinStack();\n * obj->push(val);\n * obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->getMin();\n */\n```
['Stack', 'C++']