Runtime error in 3 test cases

Code is showing runtime time error in 3 test cases.

hey @mukuljoshi2711
im not proficient with python , i can help you with java/c++
you can see this algo to understand

Time Complexity O(kn) , where k is the count of numbers to be removed and n is the length of string.
Given a non-negative integer N represented as a string, remove k digits from the number so that the new number is the smallest possible.
Note:
The length of num is less than 10002 and will be ≥ k.
The given num does not contain any leading zero.

Algorithm: Steps:

  1. Make a function remove Kdigits and pass String N and int k as parameter
    remove
    Kdigits(String N,int K)

  2. Create StringBuilder sb, inside the Function
    due to In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable. (We want to delete K char from the String)

  3. Create Stack of character S

  4. loop from value i=0 to till i<N.length()

    Inside the loop

    while (k > 0 && !s.isEmpty() && s.peek() > n.charAt(i)) {
    s.pop();
    k–;
    }
    s.push(ch);
    }

    Aim to make the smallest number
    If s.peek() > n.charAt(i) then remove bigger number
    We remove only K Character
    If stack is Empty you can’t remove anything

  5. After completion of 4th step
    Stack based on the basic principle of last-in-first-out,
    pop Character from Stack s and add First Index of Sb.until and unless Stack is Empty

  6. Above loop will not remove K Character in some cases. Then follow these steps
    Example N=”1324567” K =3
    Then sb = “124567”
    if the length of sb > length of String N - K, means Character digits are in Increasing order then remove the K Character from last.
    Sb = sb.subString(0,N-k+1)// remove total K character
    if sb.charAt(0)==’0’
    Sb = sb.subString(1)//remove leading 0’s
    If sb.length()==0
    Return “0” from function //0 is positive smallest number
    Else
    Return sb;