Java solution with an intuitive approach
This problem can be paraphrased as Delete k local maximas in the input number\nThe stack is used to track the ascent of the digits as they are fed from left to 
This problem can be paraphrased as `Delete k local maximas in the input number`\nThe stack is used to track the ascent of the digits as they are fed from left to right. As soon as a descent is encountered, it indicates that the previous digit (top of the stack) was a local maxima. In that case, the stack is popped so that it is not included as part of the result.\nThe result is crafted by continuously appending the stack tops to the left.\nIf no element was popped in the journey, it means that the k maximas are all crowded at the right extreme of the input number. In that case, we just clip those k digits and return.\nDiscard the least significant 0\'s and return the result.\n```\nclass Solution {\n    public String removeKdigits(String num, int k) {\n        if(k==0) return num;\n        if(k>=num.length()) return "0";\n        int count=0; StringBuilder sb=new StringBuilder(); Stack<Integer> stack=new Stack();\n        stack.push(Character.getNumericValue(num.charAt(0)));\n        for(int i=1;i<num.length();i++){\n            if(stack.isEmpty()||stack.peek()<=Character.getNumericValue(num.charAt(i))||count==k)\n                stack.push(Character.getNumericValue(num.charAt(i)));\n            else{\n                stack.pop();\n                count++;\n                i--;\n            }\n        }\n        while(!stack.isEmpty()) sb.insert(0,stack.pop());\n        sb=new StringBuilder(sb.toString().substring(0,num.length()-k));\n        while(sb.length()!=0&&sb.charAt(0)==\'0\') sb.deleteCharAt(0);\n        if(sb.length()==0) return "0";\n        return sb.toString();\n    }\n}\n```\n\n`Why is this greedy?`\nIts greedy because the algorithm assumes that discarding each local maxima would yield a globally optimal solution.\n**Test cases:**\n```112, 1\n10200, 1\n10, 1\n10, 2\n191, 1\n123191, 1 (3 is the first local maxima from the left so that would be the discarded digit)\n123191, 2\n12391, 1\n12391, 2\n1234567890, 9\n
['Greedy', 'Java']