#C11133. Interleaving String Construction
Interleaving String Construction
Interleaving String Construction
You are given two strings \( s_1 \) and \( s_2 \), and a target string \( t \). Your task is to determine whether \( t \) can be constructed by interleaving the characters of \( s_1 \) and \( s_2 \) while preserving the left-to-right order of the characters from each string. In other words, if we denote the interleaving operation by \( \oplus \), then we need to check whether
\( t = s_1 \oplus s_2 \)
For example, if \( s_1 = \texttt{abc} \) and \( s_2 = \texttt{def} \), one valid interleaving is \( t = \texttt{adbcef} \). However, \( t = \texttt{abdc} \) is not a valid interleaving of \( \texttt{ab} \) and \( \texttt{cd} \).
inputFormat
The first line contains an integer \( T \) denoting the number of test cases. Each test case consists of three lines:
- The first line contains a string \( s_1 \).
- The second line contains a string \( s_2 \).
- The third line contains the target string \( t \).
outputFormat
For each test case, output a single line containing "YES" if the target string can be formed by interleaving \( s_1 \) and \( s_2 \); otherwise, output "NO".
## sample5
abc
def
adbcef
ab
cd
abcd
ab
cd
abdc
aabcc
dbbca
audbbcbcac
aabcc
dbbca
audbbbaccc
YES
YES
NO
YES
NO
</p>