Best Approach💯
Please consider upvote if the solution was useful \uD83E\uDEE1\n\n# Complexity\n- Time complexity:\n- O(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\n/**\n * @pa
# Please consider upvote if the solution was useful \uD83E\uDEE1\n\n# Complexity\n- Time complexity:\n- O(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\n/**\n * @param {string} num\n * @param {number} k\n * @return {string}\n */\nvar removeKdigits = function(num, k) {\n    if(num.length ==k) return \'0\'\n    const res = []\n   for(let i=0;i<num.length;i++){\n        while(k>0 && res.length>0 && res[res.length-1]>num[i]){\n            res.pop()\n            k--\n        }\n        \n        if(res.length ==0 && num[i]==\'0\') continue\n        res.push(num[i])\n   }\n\n   while(k>0 && res.length>0) {\n    k--;\n    res.pop();\n   }\n\n   return res.length ==0 ?\'0\':res.join(\'\')\n};\n```
['JavaScript']