✔️ [Python3] MONOTONIC STACK (o^^o)♪, Explained
UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.\n\nIn order to get the smallest possible number, we have to get
**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nIn order to get the smallest possible number, we have to get rid of as many as possible big digits in the most significant places on the left. We can use a monotonically increasing stack to help us remove those big digits. When adding a new digit, we check whether the previous one is bigger than the current and pop it out. In the end, we concatenate the remaining elements from the stack and return the result.\n\nTime: **O(n)** - iteration\nSpace: **O(n)** - stack\n\nRuntime: 43 ms, faster than **77.80%** of Python3 online submissions for Remove K Digits.\nMemory Usage: 14.2 MB, less than **81.82%** of Python3 online submissions for Remove K Digits.\n\n```\nclass Solution:\n    def removeKdigits(self, num: str, k: int) -> str:\n        st = list()\n        for n in num:\n            while st and k and st[-1] > n:\n                st.pop()\n                k -= 1\n            \n            if st or n is not \'0\': # prevent leading zeros\n                st.append(n)\n                \n        if k: # not fully spent\n\t\t\tst = st[0:-k]\n            \n        return \'\'.join(st) or \'0\'\n```\n\n**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**
['Python3']