Java | C++ | Python3 | easy explanation
\nEXPLANATION:- \nSuppose If we have num 1543, k = 2\nTraverse through each digit in num, \nif you found, previous digit is greater than the current digit, dele
```\nEXPLANATION:- \nSuppose If we have num 1543, k = 2\nTraverse through each digit in num, \nif you found, previous digit is greater than the current digit, delete it.\n\nDIGITS = 1, 5, 6, 3    K = 2  res = ""\ncurrent_digit = 1, So, res = 1\ncurrent_digit = 5, So, res = 15\ncurrent_digit = 6, So, res = 156\ncurrent_digit = 3, \n\t\tNow, previous digit (6) greater than current digit (3).\n\t\tSo, del previous digit.\n\t\tres = 15  K = 1\n\t\tStill previous digit(5) is greater than current digit (3)\n\t\tres = 1, K = 0\n\t\tNow, K becomes 0\n\t\tand add remaining digits to res.\n\t\tres = 13\nSo, smallest number is 13.\n\n-> From this, we can understand if last digit of \nresult greater than the current_digit, then we need to delete it\nto get smallest number.\n-> By using this point, let\'s develop \n\tan algorithm to solve this problem.\n\nSuppose given num = 14329 and k = 2\nDo the following steps to get least number:-\n1. Traverse through each digit in num\n2. Now, pop stack \n\twhile k > 0 top of the stack is greater than current digit.\n\tthis is beacuse if stack has 1 4\n\tthen, current digit is 3, then 4 > 3 so, pop 4. \n\tbecause, the number starting with 13 is smaller than 14.\n\tThat\'s why we need to pop stack while top is \n\tgreater than current digit.\n3. After traversing through all the digits,\n    then stack looks like this = 1 2 9\n    if k > 0\n\tpop k times\n\tbecause we need to delete k digits from the number.\n4. Now, create a string variable,\n    then insert every digit in stack at the beginning.\n\tThis is because,\n\twhile popping stack 9 will first come out, then 2, and then 1.\n\tSo, add digits in reverse.\n\tHere, I am adding digits at starting position.\n\tSo, \n\twhen 9 is popped, str = 9\n\twhen 2 is popped str = 29\n\twhen 1 is popped str = 129.\n\tthat\'s how we will get number in reverse order.\n5. Now, Del any leading zeros are in string.\n6. return smallest string.\n\nIF YOU HAVE ANY DOUBTS, PLEASE COMMENT BELOW.\nIF YOU UNDERSTAND, DON\'T FORGET TO UPVOTE.\n\nTHANK YOU!!!\n\n\t\n \n```\n```\nPython3:-\nclass Solution:\n    def removeKdigits(self, num: str, k: int) -> str:    \n        stack = []\n        for digit in num:\n            while k > 0 and len(stack) > 0 and stack[-1] > digit:\n                k -= 1\n                stack.pop()  \n            stack.append(digit)\n        if k > 0:\n            stack = stack[:-k]     \n        return "".join(stack).lstrip("0") or "0"\n        \t\nJava:-\nclass Solution {\n    public String removeKdigits(String num, int k) {\n        int len = num.length();\n        if(k == 0)  return num;\n        if(k == len) return "0";\n        \n        Stack<Character> stack = new Stack<>();\n        int index = 0;\n        \n        while(index < len){\n            while(k > 0 && !stack.isEmpty() && stack.peek() > num.charAt(index)){\n                stack.pop();\n                k--;\n            }\n            stack.push(num.charAt(index++));\n        }\n        while(k-- > 0) stack.pop();\n        \n        String smallest = "";\n        while(!stack.isEmpty()) smallest = stack.pop() + smallest;\n        \n\t\t// delete leading zeros\n        while(smallest.length() > 1 && smallest.charAt(0) == \'0\')\n            smallest = smallest.substring(1);\n        \n        return smallest;\n    }\n}\n\nC++ :-\n#include <cstring>\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n        vector<char> stack;\n        if(k == num.size()) return "0";\n        int index = 0;\n        while(index < num.size()){\n            int n = stack.size();\n            while(k && n && stack[n - 1] > num.at(index)){\n                k--;\n                stack.pop_back();\n                n = stack.size();\n            }\n            stack.push_back(num.at(index++));\n        }\n        while(k-- > 0){\n            stack.pop_back();\n        }\n        int n = stack.size();\n        string small = "";\n        while(!stack.empty()){\n            small =  stack[n - 1] + small;\n            n--;\n            stack.pop_back();\n        }\n        while(small.size() > 1 && small[0] == \'0\'){\n            small = small.substr(1);\n        }\n        return small;\n    }\n};\n```\n\nI have started a series on solid principles and design patterns. If anyone is interested, please check [it](https://medium.com/@bhanu150138/mastering-solid-principles-and-design-patterns-a-blog-series-for-writing-clean-scalable-code-aae3809310db) out.
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'Java']