1
# Lets make monotonically growing stack and save the indexes of popped elements into deletes dict.2
# as soon as len(delete) == k delete those indexes from the initial string and thats the answer.3
# if len(delete) < k remove k-len(delete) chars from right and thats the answer5
def removeKdigits(self, s: str, k: int) -> str:10
for i in range(len(s)):12
while stack and s[i] < stack[-1][0]:13
delete[stack.pop()[1]] = 117
return self.deleteindexes(s, delete, k)18
stack.append([s[i], i])19
s1 = self.deleteindexes(s, delete, k)21
return str(int(s1[: len(s1) - k + len(delete)]))23
def deleteindexes(self, s, delete, k):28
int("".join([c for ind, c in enumerate(s) if ind not in delete]))31
return "".join([c for ind, c in enumerate(s) if ind not in delete])