C++ intuitive approach and easy to understand 😊
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: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> validSequence(string s, string t) {\n        int m = s.length();\n        int n = t.length();\n        // store the index k such that from current ith index of string1(s), substring [k:] of string2(t) could be obtained. \n        vector<int>vec(m);\n        vec.push_back(n);\n        vector<int>ans;\n        int j = n-1;\n        for(int i=m-1;i>=0;i--){\n            // if char matches update the vec[i] index with current index of string2(t)\n            if(j>=0 && s[i]==t[j]){\n                vec[i] = j;\n                j--;\n            }\n            // otherwise copy the length from previous ind\n            else{\n                vec[i] = vec[i+1];\n            }\n        }\n        // store the index that could be swapped -> left most \n        int swap = -1;\n        int i=0;\n        j=0;\n        while(i<m && j<n){\n            // matches -> check rest string\n            if(s[i]==t[j]){\n                j++;\n            }\n            else{\n                // if not matches check if current index could be replaced -> check if remaining part of string2 could be fulfilled by remaining part of string1\n                if(vec[i+1]<=j+1){\n                    swap = i;\n                    break;\n                }\n            }\n            i++;\n        }\n        j = 0;\n        for(int i=0;i<m;i++){\n            if(i == swap){\n                ans.push_back(i);\n                j++;\n            }\n            else{\n                if(s[i]==t[j]){\n                    ans.push_back(i);\n                    j++;\n                }\n            }\n        }\n        if(ans.size()==n) return ans;\n        else \n        return {};\n    }\n};\n```
['C++']