🎖5 Line C++ code 🎖|| clear intuition🚀 || Line by Line code Explanation🔥
Intuition\nwe will maintain 2 stack , 1st one(named s1 ) will having normal values but 2nd one (min_st)having always minimum value on it\'s top.\n\n# Approach\n
# Intuition\nwe will maintain 2 stack , 1st one(named s1 ) will having normal values but 2nd one (min_st)having always minimum value on it\'s top.\n\n# Approach\n1. push and pop operation will be always for 1st one stack(s1).\n2. push and pop operation will be done for 2nd one stack in below cases:\n\n   **a). if 2nd one stack is empty or value which is going to be push in 2nd stack is <= top of 2nd stack**\n    **b). if both stack\'s top element is equal to each-other then top element is also pop from 2nd one stack.**\n \n **NOTE: push and pop operation will be always for 1st stack(s1)**\n\n**minimum element will be always having 2nd one stack(min_st.top)*\n \n           **\uD83D\uDD25Kindly upvote if you find this helpful\uD83D\uDD25**\n\n# Complexity\n**Time complexity:\n   O(1)**\n# Space Complexity \n  **O(N)**\n    \n\n# Code\n```\nclass MinStack {\npublic:\n    stack<int>s1,min_st; // we created 2 stack (1st stack is normal,min_st.top() always having minimun element)\n    MinStack() {\n        int val;\n    }\n    void push(int val) {\n        // for normal stack, val will be always push\n        s1.push(val);\n        // for min stack(min_st), val will be push in below case\n        if(min_st.empty() || val <= min_st.top()){\n            min_st.push(val);\n        }\n    }\n    void pop() {\n        // pop and push operation will be alwayas from s1 stack\n        if(s1.top()== min_st.top()){ //if min_st ka top,s1 top ke equal h to dono stack se pop\n           min_st.pop();\n        }\n        s1.pop(); \n    }\n    \n    int top() {\n        return s1.top();\n    }\n    \n    int getMin() {\n        //min. val having always with min_st.top()\n        return min_st.top();\n    }\n    \n};\n\n```
['Stack', 'C++']