Replace the strings
Practice
3.9 (22 votes)
String manipulation
String algorithms
Algorithms
String searching
Problem
92% Success 5941 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given two strings \(S\) and \(T\) that consist of lower case Latin letters and both strings contain single '?'. You need to replace '?' with some lower case Latin letter in both strings not necessarily the same.

After that, you can apply the following operation on \(S\) any number of times:

  • Swap any two adjacent characters.

Your task is to determine if it is possible to make \(S\) equal to \(T\) if you replace '?' with a lower case Latin letter and apply the mentioned operation on \(S\) any number of times.

Input format

  • The first line contains the number of test cases \(TC\).
  • The first line of each test case contains the length of string \(S\) that is equal to the length of \(T\).
  • The second line of each test case contains the string \(S\).
  • The third line of each test case contains the string \(T\).

Output format

For each test case, print a single line. If possible to make \(S\) equal to \(T\), then print 'YES' else 'NO' without quotes.

Constraints

\(1 \leq TC \leq 1000\)

\(1 \leq |S|=|T| \leq 100000\)

The sum of lengths of string in all test cases does not exceed 500000.

Strings \(S\) and \(T\) contain exactly one '?' and lower case Latin letters.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
Easy
Points:30
16 votes
Tags:
ApprovedEasyHash MapsKMP AlgorithmOpenString Manipulation
Points:30
10 votes
Tags:
AlgorithmsString Manipulation