#C2869. Wildcard Transformation
Wildcard Transformation
Wildcard Transformation
You are given an integer N and two strings A and B. The string A may contain wildcard characters denoted by *
which can be replaced by any lowercase letter. Additionally, you are allowed to swap any characters in A an arbitrary number of times. Determine if it is possible to transform A into B by applying any number of transformations and swaps.
Formally, let \(A_{filtered}\) be the string obtained from A by removing all *
characters. The transformation is possible if and only if for every lowercase letter \(c\),
\[
\text{count}_{A_{filtered}}(c) \leq \text{count}_{B}(c),
\]
where \(\text{count}_{S}(c)\) denotes the frequency of \(c\) in string \(S\). If the condition holds, output "YES"; otherwise, output "NO".
inputFormat
The first line of the input contains an integer T, the number of test cases.
For each test case, there are three lines:
- An integer N indicating the length of string B (note that N is provided for consistency, though the solution does not depend on this value).
- A string A that may include zero or more
*
wildcard characters. - A string B consisting only of lowercase letters.
outputFormat
For each test case, output a single line containing "YES" if it is possible to transform A into B using the allowed operations; otherwise, output "NO".
## sample3
a*b
acb
YES