Is Subsequence - Problem
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. For example, "ace" is a subsequence of "abcde" while "aec" is not.
Input & Output
Example 1 — Basic Subsequence
$
Input:
s = "abc", t = "aabbcc"
›
Output:
true
💡 Note:
We can find 'a', then 'b', then 'c' in order within "aabbcc": a(a)b(b)c(c)
Example 2 — Not a Subsequence
$
Input:
s = "axc", t = "ahbgdc"
›
Output:
false
💡 Note:
We find 'a', then find 'h', 'b', 'g', 'd' but no 'x' appears before 'c'
Example 3 — Empty Subsequence
$
Input:
s = "", t = "hello"
›
Output:
true
💡 Note:
Empty string is always a subsequence of any string
Constraints
- 0 ≤ s.length ≤ 100
- 0 ≤ t.length ≤ 104
- s and t consist only of lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two strings s and t
2
Process
Check if s can be formed by deleting characters from t
3
Output
Return true if s is a subsequence of t
Key Takeaway
🎯 Key Insight: Use two pointers to scan once - no need to backtrack or try all combinations
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code