C++ || easy to understand || monotonic stack
\t// Up vote if it\'s helpful\n\t// Using ascendingly monotonic stack\n\t\n\tclass Solution {\n\tpublic:\n\t\tstring removeKdigits(string num, int k) {\n\t\t\ts
\t// Up vote if it\'s helpful\n\t// Using ascendingly monotonic stack\n\t\n\tclass Solution {\n\tpublic:\n\t\tstring removeKdigits(string num, int k) {\n\t\t\tstring ans;\n\t\t\tfor(auto& c:num) {\n\t\t\t\twhile(!ans.empty() && ans.back() > c && k) {\n\t\t\t\t\tans.pop_back();\n\t\t\t\t\tk--;\n\t\t\t\t}\n\t\t\t\tans.push_back(c);\n\t\t\t}\n\t\t\twhile(k--) \n\t\t\t\tans.pop_back();\n\t\t\twhile(ans.front() == \'0\')\n\t\t\t\tans.erase(ans.begin());\n\t\t\treturn ans.empty() ? "0" : ans;\n\t\t}\n\t};\n\t\n\t// Time complexity: O(n)\n\t// Space complexity: O(n)
['Stack', 'Greedy', 'C', 'Monotonic Stack']