C++ solution using single stack || T.C. -> O(1) ✅ & S.C. -> O(n) ✅ ||
Intuition\nWe must have to maintain minimum element track for every push and pop.\nSo we have to think accordingly.\n\n# Approach\nMaintaining minimum element a
# Intuition\nWe must have to maintain minimum element track for every push and pop.\nSo we have to think accordingly.\n\n# Approach\nMaintaining minimum element along with the current query \n(we can also use two arrays for the same, one for maintaining queries and second one for maintainig minimum elements).\n\n# Complexity\n- Time complexity:\n    O(1)  (for every operation)\n\n- Space complexity:\n    O(n)\n\n# Code\n```\nclass MinStack {\npublic:\n\nvector<pair<int,int>> arr;\n    MinStack() {\n\n    }\n    \n    void push(int val) {\n        if(arr.empty()){\n            arr.push_back({val,val});\n        }else{\n            arr.push_back({val,min(val,arr.back().second)});\n        }\n    }\n    \n    void pop() {\n        arr.pop_back();\n    }\n    \n    int top() {\n        return arr.back().first;\n    }\n    \n    int getMin() {\n        return arr.back().second;\n    }\n};\n\n```
['C++']