User friendly Code | | C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> validSequence(string word1, string word2) {\n        int n = word1.size(), m = word2.size(), skip = 0;\n        vector<int> last(m, -1);\n        for (int i = n - 1, j = m - 1; i >= 0 && j >= 0; --i)\n            if (word1[i] == word2[j])\n                last[j--] = i;\n\n        vector<int> res;\n        \n        for (int i = 0, j = 0; i < n && j < m; ++i) {\n            if (word1[i] == word2[j]) {\n                res.push_back(i);\n                j++;\n            }\n            else if(skip == 0 && (j == m - 1 || i < last[j + 1])){\n                //it means all the chars from j+1 are there so we can replace j\n                res.push_back(i);\n                skip++;j++;\n            }\n        }\n        return res.size() == m ? res : vector<int>();\n    }\n};\n```
['C++']