Shortest and fastest 1-stack and 2-stack solutions
2-stack solution may use less memory (ironically) since we don't save the 'min' for every pushed element. \nIf there are a lot of repeated elements, we may save
2-stack solution may use less memory (ironically) since we don't save the 'min' for every pushed element. \nIf there are a lot of repeated elements, we may save even more memory by  introducing a 'count' for each 'min'.\n\nCannot use vector (will get memory limit error), as vector doubles its capacity when full, whereas deque has a better capacity management strategy.\n\n2 deque:\n\n        deque<int> stack;\n        deque<int> mins;\n        \n        void push(int x) {\n            int themin = mins.size() ? mins.back() : x;\n            stack.push_back(x);\n            if (x<=themin)\n                mins.push_back(x);\n        }\n    \n        void pop() {\n            if (stack.back()==mins.back())\n                mins.pop_back();\n            stack.pop_back();\n        }\n    \n        int top() {\n            return stack.back();\n        }\n    \n        int getMin() {\n            return mins.back();\n        }\n   \n1 deque (save current min for every pushed elem):\n\n\n    typedef pair<int,int> pairt;\n\n        deque<pairt> stack;\n\n        void push(int x) {\n            if (stack.size())\n                stack.push_back(make_pair(x, min(x,getMin()) ));\n            else \n                stack.push_back(make_pair(x, x));\n        }\n    \n        void pop() {\n            stack.pop_back();\n        }\n    \n        int top() {\n            return stack.back().first;\n        }\n    \n        int getMin() {\n            return stack.back().second;\n        }
[]