#K3916. Subsequence Transformation Check
Subsequence Transformation Check
Subsequence Transformation Check
Given two strings S
and T
, determine if T
can be obtained as a subsequence of S
. In other words, you can remove some characters from S
without changing the order of the remaining characters to obtain T
.
Formally, string T
is a subsequence of S
if there exists a sequence of indices \( i_1, i_2, \dots, i_k \) such that \( 1 \le i_1 < i_2 < \cdots < i_k \le |S| \) and \( S[i_1]S[i_2]\cdots S[i_k] = T \).
Examples:
- For
S = "abacdef"
andT = "acdf"
, the answer is YES. - For
S = "xyaab"
andT = "abc"
, the answer is NO.
inputFormat
The input consists of two lines. The first line contains the string S
and the second line contains the string T
.
outputFormat
Output a single line containing YES
if T
is a subsequence of S
, or NO
otherwise.
abacdef
acdf
YES