<p>Given string num representing a non-negative integer <code>num</code>, and an integer <code>k</code>, return <em>the smallest possible integer after removing</em> <code>k</code> <em>digits from</em> <code>num</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> num = &quot;1432219&quot;, k = 3
<strong>Output:</strong> &quot;1219&quot;
<strong>Explanation:</strong> Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> num = &quot;10200&quot;, k = 1
<strong>Output:</strong> &quot;200&quot;
<strong>Explanation:</strong> Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> num = &quot;10&quot;, k = 2
<strong>Output:</strong> &quot;0&quot;
<strong>Explanation:</strong> Remove all the digits from the number and it is left with nothing which is 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= k &lt;= num.length &lt;= 10<sup>5</sup></code></li>
	<li><code>num</code> consists of only digits.</li>
	<li><code>num</code> does not have any leading zeros except for the zero itself.</li>
</ul>

sys.set_int_max_str_digits(int(1e5)) 
from collections import deque

class Solution:
    def removeKdigits(self, num: str, k: int) -> str:
        ret, n, ind = 0, len(num), 0
        A = [deque() for _ in range(10)]


        def key(c):
            return ord(c) - ord('0')

        for left in range(n-k, 0, -1):
            while ind <= n-left:
                A[key(num[ind])].append(ind)
                ind += 1
            
            buck_ind = min(range(10), key=lambda t_ind: 1 - min(1, len(A[t_ind])))
            min_ind = A[buck_ind][0]
            ret = ret * 10 + key(num[min_ind])

            for dq in A:
                while dq and dq[0] <= min_ind:
                    dq.popleft()

        
        return str(ret)



        
19000