C++ || Easy Understanding || Simple Logic With Explanation|| Without Stack
\n* Basic String Traverse Problem \n* UpVote if You Like It\n\n\n\n\n\n//Logic Is Pretty Simple I have to Just Find the digit which are greater than from next o
```\n* Basic String Traverse Problem \n* UpVote if You Like It\n```\n\n\n```\n\n//Logic Is Pretty Simple I have to Just Find the digit which are greater than from next one or we can say \n//that previous digit which are greater than from next one and make it as smaller as a possible\n\nclass Solution {\npublic:\n    string removeKdigits(string num, int k)\n    {\n          string res="";\n          if(num.length() == k)// if the length of the string is equal to the length of string which we have to return\n              return "0"; \n          for (int i = 0; i < num.length(); i++)\n          {\n              while(res.size()>0  && res.back() > num[i] && k)  //removig all those which digit which are greater than next one \n              {\n                     res.pop_back();\n\t\t\t\t\t k--;\n              }\n              if(res.size() > 0 || num[i]!=\'0\')     // pushing all digit one by one and we should not add any zeros if res length is zero because, it may lead to add zeros at the front that doesn\'t make sense  \n              {\n                 res.push_back(num[i]);\n              }\n          }\n           while(res.size() && k )    //maybe there is no digit such that which satify the condition but we have to remove some digt than we are removing last k digit \n           {\n              res.pop_back(); \n              k--;\n           }\n          return res.empty() ? "0" : res;   //if resulting string contain some thing or not\n    }\n};\n```
['String', 'C++']