Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Maintain two pointers: i and j. We need to perform a similar operation: while t[0:i] + t[j:n] is not a subsequence of the string s, increase j.
We can check the condition greedily. Create the array leftmost[i] which denotes minimum index k, such that in prefix s[0:k] exists subsequence t[0:i]. Similarly, we define rightmost[i].
If leftmost[i] < rightmost[j] then t[0:i] + t[j:n] is the subsequence of s.