Java Reverse Greedy Solution
Code\njava []\nclass Solution {\n    public int[] validSequence(String word1, String word2) {\n        int n = word1.length(), m = word2.length(), revGreedyMatc
# Code\n```java []\nclass Solution {\n    public int[] validSequence(String word1, String word2) {\n        int n = word1.length(), m = word2.length(), revGreedyMatchInd[] = new int[m];\n        Arrays.fill(revGreedyMatchInd, -1);\n        for(int i = n - 1, j = m - 1; j >= 0 && i >= 0; i--){\n            if(word1.charAt(i) == word2.charAt(j))    revGreedyMatchInd[j--] = i;\n        }\n        boolean canSkip = true;\n        int j = 0;\n        for(int i = 0; i < n && j < m && m - j <= n - i; i++){\n            if(word1.charAt(i) == word2.charAt(j)){\n                revGreedyMatchInd[j++] = i;\n            }else if(canSkip && (j == m - 1 || i < revGreedyMatchInd[j + 1])){\n                revGreedyMatchInd[j++] = i;\n                canSkip = false;\n            }else if(!canSkip && revGreedyMatchInd[j] == -1)    break;\n        }\n        \n        return j == m ? revGreedyMatchInd : new int[0];\n    }\n}\n```
['Java']