My Solution
\n/**\n * Time Complexity: O(n1)\n * Space Complexity: O(n1)\n * where `n1` is the length of the string `word1`\n */\nclass Solution {\n public:\n  vector<int> 
```\n/**\n * Time Complexity: O(n1)\n * Space Complexity: O(n1)\n * where `n1` is the length of the string `word1`\n */\nclass Solution {\n public:\n  vector<int> validSequence(const string &word1, const string &word2) {\n    const int n1 = static_cast<int>(word1.size());\n    const int n2 = static_cast<int>(word2.size());\n    int suffices[n1 + 1];\n    suffices[n1] = n2;\n    for (int i1 = n1 - 1, i2 = n2 - 1; i1 > -1; ) {\n      if (i2 > -1 && word1[i1] == word2[i2]) {\n        suffices[i1] = i2;\n        --i2;\n      } else {\n        suffices[i1] = suffices[i1 + 1];\n      }\n      --i1;\n    }\n    \n    vector<int> ret;\n    for (int changed = 0, i1 = 0, i2 = 0; i1 < n1 && i2 < n2; ) {\n      if (word1[i1] == word2[i2] || (changed == 0 && suffices[i1 + 1] <= i2 + 1)) {\n        if (word1[i1] != word2[i2]) {\n          changed = 1;\n        }\n        ret.emplace_back(i1);\n        ++i2;\n      }\n      ++i1;\n    }\n    return static_cast<int>(ret.size()) == n2 ? ret : vector<int>{};\n  }\n};\n```
[]