A gift-card terminal reads a long stream of characters and must confirm that a shorter target pattern is hidden inside it, in order, as a subsequence. Pattern b is a subsequence of stream a if b can be formed by deleting zero or more characters from a without changing the order of the remaining characters.
Given a and b, decide whether b is a subsequence of a.
Line 1: the stream string a.
Line 2: the pattern string b.
Print YES if b is a subsequence of a, otherwise print NO.
a <= 40b <= 40Example 1
Input
axbxcx abc
Expected
YES
Explanation
Scanning left to right, a, then b, then c all appear in order inside axbxcx, so b is a subsequence.
Example 2
Input
abc acb
Expected
NO
Explanation
After matching a and then c, there is no b remaining to the right, so acb is not a subsequence of abc.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →