C++|| Simple solution || Mono Stack || Using string as stack
Approach\nif we have n digits and remove k digits so total digits = (n-k) which will always be constant unless we have leading zeroes which will be handled late
# Approach\nif we have n digits and remove k digits so total digits = (n-k) which will always be constant unless we have leading zeroes which will be handled later.\nA number is minimum when its leftmost digits are as small as possible.\nso if we get bigger digit at first and then get smaller. we should remove the bigger digit. How do we achieve that ? or how do i keep a track of which was my previous bigger digit ? we can use the stack.\n\nNow what if all the numbers are increasing like 1 2 2 3 4 with  k=2.\nAs per the above logic all elements will be pushed in stack with no removal. if this is the case then we will pop out last elements until k becomes zero. as the values stored in stack will be mono increasing if k is not zero. \n  now we will simply pop last 2 elements and smallest will be 1 2 2.\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n\n        //using stack\n        stack<int> st;\n        int n = num.size(),i=0;\n        if(n == k) return "0";\n        string ans="";\n        for(;i<n;i++){\n            int ele = num[i]-\'0\';\n            while(!st.empty() && k>0 && st.top() > ele){ \n                k--; \n                st.pop();\n            }\n            st.push(ele);\n        }\n        //if k not zero simply remove the stack top as we are storing mono increasing value\n        while(!st.empty()){\n            if(k==0){\n                  ans += st.top()+\'0\';\n            }else{\n                k--;\n            }\n          st.pop();\n        }\n    \n        reverse(ans.begin(),ans.end());\n        i=0,n=ans.size();\n        //if we have leading zeroes handle it by using this\n        // take for example 1000000000 k=1 we remove 1 but all we are left with leading zeroes.\n        while(i<n && ans[i] == \'0\') i++;\n        if(i == n) return "0"; //means all leading zeroes\n        return ans.substr(i,n-i);\n    }\n};\n```\n\n# Code 2 without stack\n```\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n\n        int n = num.size(),i=0;\n        if(n == k) return "0";\n        string ans="";\n        for(;i<n;i++){\n            while(ans.size()>0 && k>0 && ans.back() > num[i]){ \n                k--; \n                ans.pop_back();\n            }\n            ans.push_back(num[i]);\n        }\n        //if k not zero simply remove the string back as we are storing mono increasing value\n        while(k>0){\n            ans.pop_back();\n            k--;\n        }\n        //if we have leading zeroes handle it by using this\n        // take for example 1000000000 k=1 we remove 1 but all we are left with leading zeroes.\n        i=0,n=ans.size();\n        while(i<n && ans[i] == \'0\') i++;\n        if(i == n) return "0"; //means all leading zeroes\n        return ans.substr(i,n-i);\n    }\n};\n```
['Stack', 'Monotonic Stack', 'C++']