#C8381. Reordering to Form Subsequence
Reordering to Form Subsequence
Reordering to Form Subsequence
You are given two strings s and t. Determine whether it is possible to reorder the characters of s to form a new string that contains t as a subsequence.
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. In other words, for each character in t, its occurrence in the reordered string should appear in the same order as in t.
Example:
- For
s = "abcde"
andt = "ace"
, the answer isYES
because after reorderings
(or even without reordering)ace
appears as a subsequence. - For
s = "xyz"
andt = "abc"
, the answer isNO
becauses
does not contain the required characters.
Note that the reordering can be arbitrary as long as the count of each character in s is not less than that in t.
inputFormat
The input is given via stdin and consists of multiple test cases.
The first line contains a single integer T
(the number of test cases).
Each of the next T
lines contains two space-separated strings s
and t
.
Both strings contain only lowercase English letters.
outputFormat
For each test case, output a single line with YES
if it is possible to reorder s
to obtain a string that contains t
as a subsequence. Otherwise, output NO
.
The output should be written to stdout.
## sample3
abcde ace
abacaba aba
xyz abc
YES
YES
NO
</p>