Python using stack O(n)
The high-level logic is to get as small number as possible from the most siginificant digit (leftmost). So using a stack, we just keep exchange digit if it\'s s
The high-level logic is to get as small number as possible from the most siginificant digit (leftmost). So using a stack, we just keep exchange digit if it\'s smaller than the previous one until k digits are already removed.\nCorner case is when the digits are non-decreasing. Add another loop or do slicing to remove k digits on the right.\n\n```\nclass Solution(object):\n    def removeKdigits(self, num, k):\n        """\n        :type num: str\n        :type k: int\n        :rtype: str\n        """\n        if len(num) <= k:\n            return \'0\'\n        \n        stack = []\n        \n        for digit in num:\n            while k> 0 and stack and int(stack[-1]) > int(digit): \n                stack.pop()\n                k -= 1\n            stack.append(digit)\n        \n        while k > 0: #corner case 112 remove 1\n            stack.pop()\n            k -= 1\n        return \'\'.join(stack).lstrip(\'0\') or \'0\'\n\n```
[]