Two Pointers· 15 min

Is Subsequence

LeetCode #392 · Easy · Interactive step-by-step visualization

Setup

Example inputs = "abc", t = "ahbgdc"
Step 1 / 13

Current step

1 / 13

Compare 'a' with 'a'. The source pointer advances only when its required character is found. Characters match.

Step log

matched

0 / 3

Active cursor
Comparing
Best or completed
Leaving or removed
is-subsequence.java
1public boolean isSubsequence(String s, String t) {
2 int source = 0;
3 for (int target = 0; target < t.length() && source < s.length(); target++) {
4 if (s.charAt(source) == t.charAt(target))
5 source++;
6 }
7 return source == s.length();
8}
● Java
Time
O(n)
Space
O(1)
Pattern
two pointers
Frames
13