visual walkthrough
Is Subsequence
Greedy matching with two pointers over two strings.
The idea
A subsequence keeps the order of letters but may skip some. So greedily match: keep a pointer on the next letter of s you still need and move along t, advancing it whenever t shows that letter.
If you reach the end of s, every letter was found in order.
Complexity
| approach | time | space |
|---|---|---|
| Two pointers | O(n) | O(1) |