Easy to understand c++ with explanation
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    // Testcase:\n    // word 1 :      m m m a b z z z d e f x x x\n    // suffix_match :3 3 3 3 3 3 3 3 3 2 1 0 
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    // Testcase:\n    // word 1 :      m m m a b z z z d e f x x x\n    // suffix_match :3 3 3 3 3 3 3 3 3 2 1 0 0 0\n\n    // word 2:       a b c\n\n    vector<int> validSequence(string word1, string word2) {\n        int n = word1.size(), m = word2.size();\n\n        //creating suffix_match array\n        vector<int>suffix_match(n+1, 0);\n        // int suffix_match[n+1] = {0};\n        int i=n-1, j=m-1;\n        while(i>=0 && j>=0){\n            if(word1[i] == word2[j]){\n                suffix_match[i] = 1+suffix_match[i+1];\n                i--; j--;\n            }\n            else{\n                suffix_match[i]  = suffix_match[i+1];\n                i--;\n            }\n        }\n        while(i>=0){\n            suffix_match[i] = suffix_match[i+1];\n            i--;\n        }\n\n        vector<int>ans; //store ans\n        i=0,j=0;    \n        bool flag = false; //check whether char changing occured or not\n        while(i<n && j<m){\n            if(word1[i] == word2[j]){  //matched case\n                ans.push_back(i);\n                i++; j++;\n            }\n            else{\n                //unmatched case, we change the ith to make it similar to jth only if m-j-1 >= suffix_match[i+1]\n                if(flag==false && suffix_match[i+1] >= m-j-1){\n                    ans.push_back(i);\n                    i++; j++;\n                    flag = true;\n                }\n                else{\n                    i++;\n                }\n            }\n        }\n\n        if(ans.size() == m)\n            return ans;\n        else\n            return {};\n    }\n};\n```
['C++']