Easy C++ solution | 0ms - 100% faster | Explained
\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n        string res="";\n        \n        for(auto c : num){                        
```\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n        string res="";\n        \n        for(auto c : num){                                                //iterating over the whole string\n\t\t\t\twhile(res.length() && res.back()>c && k){  //while k>0 and there\'s still characters in res and last char is greater than current char\n                res.pop_back();\n                k--;\n            }\n            \n            if(res.length() || c!=\'0\')        //to ensure that res doesnt have leading 0\'s\n                res.push_back(c);\n        }\n        \n        while(res.length() && k){             //if k is still greater than 0, delete characters from back\n            k--;\n            res.pop_back();\n        }\n        \n        return res.empty()? "0" : res;         //returning solution\n    }\n};\n```
['Greedy', 'C', 'C++']