text: #include <gtest/gtest.h>
  #include <iostream>
  #include <string>
  
  using namespace std;
  
  /**
   * This file is generated by leetcode_add.py
   *
   * 402.
   *      Remove K Digits
   *
   * ––––––––––––––––––––––––––––– Description –––––––––––––––––––––––––––––
   *
   *   Given string num representing a non-negative integer ‘num’ , and an
   *   integer ‘k’ , return “the smallest possible integer after removing”
   *   ‘k’ “digits from” ‘num’ .
   *
   * ––––––––––––––––––––––––––––– Constraints –––––––––––––––––––––––––––––
   *
   *   • ‘1 ≤ k ≤ num.length ≤ 10⁵’
   *   • ‘num’ consists of only digits.
   *   • ‘num’ does not have any leading zeros except for the zero itself.
   *
   */
  
  struct q402 : public ::testing::Test {
    // Leetcode answer here
    class Solution {
     public:
      string removeKdigits(string num, int k) {
        if (k == 0)                   return num;
        else if (num.empty() == true) return "0";
        string res = "";
        for (const auto &c : num) {
          while (k > 0 && res.empty() == false && res.back() > c) {
            res.pop_back();
            --k;
          }
          if (res.empty() == false || c != '0') {
            res.push_back(c);
          }
        }
        while (res.empty() == false && k > 0) {
          res.pop_back();
          --k;
        }
        return res.empty() ? "0" : res;
      }
    };
  
    class Solution *solution;
  };
  
  TEST_F(q402, sample_input01) {
    solution = new Solution();
    string num = "1432219";
    int k = 3;
    string exp = "1219";
    string act = solution->removeKdigits(num, k);
    EXPECT_EQ(act, exp);
    delete solution;
  }
  
  TEST_F(q402, sample_input02) {
    solution = new Solution();
    string num = "10200";
    int k = 1;
    string exp = "200";
    string act = solution->removeKdigits(num, k);
    EXPECT_EQ(act, exp);
    delete solution;
  }
  
  TEST_F(q402, sample_input03) {
    solution = new Solution();
    string num = "10";
    int k = 2;
    string exp = "0";
    string act = solution->removeKdigits(num, k);
    EXPECT_EQ(act, exp);
    delete solution;
  }