My Solution
\n/**\n * one important observation\n * assume there exists a two-character substring "`c1``c2`"\n * if `c1` is greater than `c2`,\n * the substring "`c1``c2`" 
```\n/**\n * one important observation\n * assume there exists a two-character substring "`c1``c2`"\n * if `c1` is greater than `c2`,\n * the substring "`c1``c2`" can be transformed into "`c2``c1`"\n * so for any character `c`, whose index is `i`, in string `s`,\n * it can be moved to any position `j`, where `j` < `i` and\n * any characters from `j` to (`i` - 1) are greater than `c`\n *\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the string `s`\n */\nclass Solution {\n public:\n  bool isTransformable(const string &s, const string &t) {\n    constexpr int digits = 10;\n    constexpr int zero = \'0\';\n    const int n = static_cast<int>(s.size());\n    vector<int> indices[digits];\n    for (int i = 0; i < n; ++i) {\n      indices[s[i] - zero].emplace_back(i);\n    }\n    int positions[digits];\n    memset(positions, 0, sizeof(positions));\n    for (int i = 0; i < n; ++i) {\n      const int digit = t[i] - zero;\n      const vector<int> &digit_indices = indices[digit];\n      const int digit_position = positions[digit]++;\n      if (digit_position >= digit_indices.size()) {\n        // there exist more digits `digit` in `t` than in `s`\n        // so it\'s impossible to transform `s` into `t`\n        return false;\n      }\n      \n      const int index = digit_indices[digit_position];\n      for (int less_digit = 0; less_digit < digit; ++less_digit) {\n        if (positions[less_digit] < indices[less_digit].size() && indices[less_digit][positions[less_digit]] < index) {\n          // there exist a less digit before the current digit `digit` in the string `s`\n          // so it\'s impossible to move the digit `digit` to the correct position\n          return false;\n        }\n      }\n    }\n    return true;\n  }\n};\n```
[]