Remove K Digits using Stack [CPP][C++][Easy to understand][Well explained]
Basic Intusion:\nremove the i th character if (i+1)th character is lesser.\n\nCorner cases:\n1. check whether value of k is lesserthan length of the string.\n2.
**Basic Intusion:**\nremove the ***i*** th character if (***i+1***)th character is lesser.\n\n**Corner cases:**\n1. check whether value of k is lesserthan length of the string.\n2. after travesing whole string, is there any k left? (if the digits are in increasing order)\n3. remove the leading zeroes if there are any.\n4.  if string become empty return "0"\n\n**Function Explanation:**\nstring removeKdigits(string num, int k) {\n1. to check the 1st corner case. \n2. create a stack \'s\', to perform the remove operations. \n3. Run the for loop for entire string.\n4. If stack is empty push first character of the num string \n5. else\n6.  a. boundry case to check whether stack is empty or not\n     b.  to check whether top is greaterthan ith character of the string\n\t c.  to track the value of k \n7.  if all the above three saticifies \n\ta. remove top element \n\tb.decrease the value of k \n8. if not push the number.\n9. to check the 2nd corner case. if there is any \'k\' left, pop the elements of stack and decrement value of k \n10.  after performing the stack operations check whether stack empty or not, if empty return "0"\n11.  return the string in reverse order "ans = s.top()+ans" using this.\n12.  to check corner case 3 and 4 \n13.  check if there any leading zeros, if there are return the string from non zeroth character. else return "0"\n}\n```\nstring removeKdigits(string num, int k) {\n        \n        if(k >= num.size()) return "0";\n        \n        stack<char>s;\n        \n        for(int i=0; i<num.size();i++){   \n            if(s.empty()) s.push(num[i]);    \n            else{\n            while(!s.empty() && s.top() > num[i] && k>0){     //Main Logic\n                s.pop();\n                k--;\n            }\n                   s.push(num[i]);\n            }\n        } \n\t\t\n\t\t/* Corner case 2: if the array reaches end, but some \'k\' value is left. It means, \n\t\t* if the numbers are in increasing order, k can\'t be decremented. for that we are\n\t\t* removing the remaining k elements from stack.\n\t\t*/\n\t\t\n        while(k>0){\n            s.pop();\n            k--;\n        }\n\t\t\n        if(s.empty()) return "0";\n\n        string ans; \n        while(!s.empty()){\n            ans = s.top()+ans;     //reverse the stack\n            s.pop();\n        }\n        int i=0;\n\t\t/* corner case 3: count the leading number of zeros*/\n        while(ans[i] == \'0\'){\n            i++;\n        }\n\t\t\n        return (ans.substr(i) == "")? "0": ans.substr(i);\n    }\n\n```\n\n
['C', 'C++']