Given strings X and Y, determine whether X is a subsequence of Y. The empty string is regarded as a subsequence of every string. (E.g., ''
and 'anna'
are subsequences of 'banana'
.)
Input
- X, a possibly-empty case-sensitive alphanumeric string
- Y, a possibly-empty case-sensitive alphanumeric string
Output
- True or False (or equivalents), correctly indicating whether X is a subsequence of Y.
I/O examples
X Y output
'' 'z00' True
'z00' 'z00' True
'z00' '00z0' False
'aa' 'anna' True
'anna' 'banana' True
'Anna' 'banana' False
Criteria
- The shortest program wins, as determined by the number of bytes of source code.
Example programs
- Several programs that could be adapted are in this related posting.
anna
is a subsequence (but not a substring) ofbanana
. String X is a subsequence of string Y just if X can be obtained from Y by deleting zero or more of the elements of Y; e.g., deleting theb
and the seconda
frombanana
givesanna
. – r.e.s. Apr 26 '12 at 13:33