#K89977. Subsequence Check
Subsequence Check
Subsequence Check
Given two strings A and B, determine if A is a subsequence of B. In other words, check whether all characters of A appear in B in the same order (not necessarily contiguous). Formally, A is a subsequence of B if there exists indices \(i_1, i_2, \ldots, i_{|A|}\) such that \(1 \leq i_1 < i_2 < \cdots < i_{|A|} \leq |B|\) and for every \(j\) (\(1 \leq j \leq |A|\)), \(A[j]=B[i_j]\). Note that an empty string is always a subsequence of any string, including another empty string.
inputFormat
The input begins with an integer T (\(T \geq 1\)) on the first line representing the number of test cases. Each test case consists of two lines:
- The first line contains the string A.
- The second line contains the string B.
Note: The strings can be empty.
outputFormat
For each test case, output a single line containing either YES
or NO
. Output YES
if the string A is a subsequence of the string B, otherwise output NO
.
6
abc
ahbgdc
axc
ahbgdc
ace
abcde
aec
abcde
ahbgdc
ahbgdc
YES
NO
YES
NO
YES
YES
</p>