```
public string RemoveKdigits(string num, int k)
{
if(num.Length == k) return "0";
while(k-->0)
{
if(num[1] == '0')
{
int firstNotZero = 1;
while(firstNotZero < num.Length && num[firstNotZero] == '0') firstNotZero ++;
num=num.Remove(0,firstNotZero);
}
else
{
int startIndex = 0;
while(startIndex < num.Length - 1 && num[startIndex] <= num[startIndex + 1]) startIndex ++;
num=num.Remove(startIndex,1);
}
}
if(num == "") return "0";
return num;
}
```