<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>

class Solution {
public:
    string removeKdigits(string num, int k) {
        int n = num.size();
        stack<int> stk;

        // if stk.top() -'0' > num[i] - '0' otherwise push
        for(int i=0 ; i<n ; i++){
            while( !stk.empty() && k>0 && stk.top() -'0' > num[i] - '0'){
                stk.pop();
                k=k-1;
            }
            stk.push(num[i]);
        }
        if(stk.empty()) return "0";

        // solving the edge cases
        // if num's value in increasing order 123456 like that
        while( k> 0) {
            stk.pop();
            k--;
        }
        if(stk.empty()) return "0";

        // from stack to string 
        string res = "";
        while( !stk.empty()){
            res += stk.top();
            stk.pop();
        }

        // removing the leading zeroes from the front of the answer 
        while( res.size() != 0 && res.back() == '0'){
            res.pop_back();
        }
        reverse(res.begin(),res.end());
        if(res.empty()) return "0";
        return res;


    }
};


/*

 if( n == k ) return "0";
        string nums = num ;
        for( int i=0 ; i<n-1 ; i++){

            // starting ke liye eak edge case or lena padega 
            
            if( k > 0 && (nums[i]==0 || nums[i+1] == 0) ){
                nums.erase(i);
                k--;
            }
            else if( (k>0 && i>0 ) && (nums[i] >= nums[i-1] && nums[i]>=nums[i+1]) ){
                nums.erase(i);
                k--;
            }
        }
        return num;
*/
12600