DSA problem
Is Subsequence
Given two strings s and t, return true if s is a subsequence of t, and false otherwise.
A subsequence of a string is a new string formed from the original by deleting some (possibly zero) characters without disturbing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde", while "aec" is not.
The check is order-sensitive: every character of s must appear in t in the same sequence, though not necessarily consecutively.
Examples
Example 1
Input:
s = "abc", t = "ahbgdc"Output:
trueExplanation: Reading t left to right we find a, then b, then c in order, so "abc" is a subsequence.
Example 2
Input:
s = "axc", t = "ahbgdc"Output:
falseExplanation: We can match a and c, but there is no x in t, so "axc" is not a subsequence.
Constraints
- 0 <= s.length <= 100
- 0 <= t.length <= 10^4
- s and t consist only of lowercase English letters.
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.