gg [VERY EASY TO UNDERSTAND SOLN IN 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 w1, string w2) {\n        int n = w1.size();\n        int m = w2.size();\n        vector<int> ans;\n        vector<int> suff(n+1,0);\n\n        int i = n-1, j = m-1;\n        int maxi = 0;\n\n        while(i >= 0 && j >= 0)\n        {\n            if(w1[i] == w2[j])\n            {\n                suff[i] = suff[i+1] + 1;\n                maxi = max(maxi,suff[i]);\n                i--;\n                j--;\n            }\n\n            else\n            {\n                suff[i] = suff[i+1];\n                maxi = max(maxi,suff[i]);\n                i--;\n            }\n        }\n\n        for(int i = 0; i < n; i++)\n        {\n            if(suff[i] == 0)\n            suff[i] = maxi;\n            else\n            break;\n        }\n\n        i = 0, j = 0;\n        bool used = 0;\n\n        while(i < n && j < m)\n        {\n            if(w1[i] == w2[j])\n            {\n                ans.push_back(i);\n                i++;\n                j++;\n            }\n\n            else if(!used && suff[i+1] >= (m - 1 - j))\n            {\n                ans.push_back(i);\n                used = 1;\n                i++;\n                j++;\n            }\n\n            else\n            i++;\n        }\n\n        // return suff;\n\n        if(ans.size() == m)\n        return ans;\n\n        return {};\n    }\n};\n```
['C++']