[C++] | O(n) | stack | simple logic | detail explanation
logic: In stack push an element if it is bigger than top of the stack\nFor Example:- num = "1211" and k = 2\ninsert first element stack=1\n1211 here 1(stack top
logic: In stack push an element if it is bigger than top of the stack\nFor Example:- num = "1211" and k = 2\ninsert first element **stack=1**\n1**2**11 here 1(stack top) < 2 so take it **stack=12**  k=2\n12**1**1 here 2(stack top) > 1 so remove all elements greater than 1 alongside reducing k ,then take 1 **stack=11**  k = 1\n121**1** here 1(stack top) =1 so take it **stack=111** k=1\nsince k!=0 take out k elements from stack   **stack=11** k=0\n**Result:- 11**\n```\nstring removeKdigits(string num, int k) {\n        if(num.length()==k)return "0";\n        // get all eligible elements in a stack\n\tstack<char> s;\n        for(char c:num){\n            while(k && !s.empty() && int(s.top())>int(c)){s.pop();k--;} \n            s.push(c);\n        } \n        //if still no change in k then remove k elements\n        if(k) while(k--){s.pop();}\n        // remove leading 0s ,if present\n        stack<char> t;\n        while(!s.empty()){t.push(s.top());s.pop();}\n        while(t.top()==\'0\'&&t.size()!=1)t.pop();\n        //return the answer\n        num="";\n        while(!t.empty()){num.push_back(t.top());t.pop();}\n        return num;\n    }\n```\nplease upvote | thank you
[]