Easiest greedy solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThe only reason at a certain point we are not sure to deduct a character 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe only reason at a certain point we are not sure to deduct a character at an index i is safe because we dont\'t know if this character is a part of w2 which is not matching right now but we won\'t also find it later because it\'s a single piece.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n+m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n+1) -> O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```typescript []\nfunction validSequence(w1: string, w2: string): number[] {\n    const n = w1.length;\n    const m = w2.length;\n\n    // How many characters matched from back at a certain i of word 1\n    let r = m - 1;\n    const res = Array.from({ length: n + 1 }, () => 0);\n\n    for (let i = n - 1; i >= 0; i--) {\n        res[i] = res[i + 1];\n        if (r >= 0 && w2[r] === w1[i]) {\n            r--;\n            res[i]++;\n        }\n    }\n\n    const ans: number[] = [];\n    let l = 0;\n    let ok = true;\n\n    for (let i = 0; i < n && l < m; i++) {\n        if (w1[i] === w2[l]) {\n            ans.push(i);\n            l++;\n        } \n        //one charcater can be differrent decided by ok flag\n        else if (ok && res[i + 1] >= m - l - 1) {\n            ok = false;\n            ans.push(i);\n            l++;\n        }\n    }\n\n    return ans.length === m ? ans : [];\n}\n\n```
['TypeScript']