Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use two pointers, one for each string. Advance the pointer for t on every iteration. Only advance the pointer for s when the characters match. If all characters in s are matched by the end, s is a subsequence of t.
A subsequence preserves order but not contiguity. By greedily matching each character of s to the earliest possible position in t, we determine if the ordering can be preserved.
Updated Feb 2026