java solution with algorithm easy explanation
//algorithm\n        //create stack\n        //push the element before check for the all elemnets in stack \n        //if the currentElement lesser then element
//algorithm\n        //create stack\n        //push the element before check for the all elemnets in stack \n        //if the currentElement lesser then elements in stack then remove the element  in stack\n        //special case: if the stack is dont the add the 0 beacause that would be the leading zero\n        //if traverse the string k not equal zero remove last elements in stack\n        //if stack is empty the given length and the k length is equal return 0\n        //after you get the all elements and reverse\n\n\tclass Solution {\n    public  String removeKdigits(String str, int k) {\n\n        char []nums = str.toCharArray();\n        int n = nums.length;\n\n        Stack<Character>st = new Stack<>();\n\n        for(int i=0;i<n;i++){\n\n            // remove strictly decreasing sequence\n            \n            while(!st.isEmpty() && st.peek()>nums[i] && k-- >0)\n                st.pop();\n\n            // prevent leading zeros\n            if (st.isEmpty() && nums[i] == \'0\') continue;\n            st.push(nums[i]);\n        }\n\n        // k is not zero then remove last digits from the sequence\n        while(!st.isEmpty() && k-- >0){\n            st.pop();\n        }\n\n        if(st.isEmpty()) return "0";\n\n        StringBuilder sb= new StringBuilder();\n\n        while(!st.isEmpty())\n            sb.append(st.pop());\n\n        return sb.reverse().toString();\n    }\n}
['String', 'Stack', 'Java']