Make the strings equal
Practice
3.5 (17 votes)
String algorithms
Algorithms
String
String searching
Problem
57% Success 4553 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You are given two strings \(S\) and \(T\) consisting of lower case Latin letters. Your task is to determine if you can make \(S\) equal to \(T\) using the following operation:
- Swap any two adjacent characters in \(S\) and also swap any two adjacent characters in \(T\).
Note: It is necessary to swap both the strings and it is not optional if you are applying operation.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integer denoting the length of \(S\).
- The second line of each test case contain string \(S\).
- The third line of each test case contain string \(T\).
Output format
Print \(T\) lines. For each test case:
- Print a single line 'YES' if you can make \(S\) equal to \(T\) else 'NO'.
Constraints
\( 1\leq T \leq 20000 \)
\(1 \leq |S| =|T| \leq 200000 \)
The sum of \(|S|\) over all test cases is less than or equal to \(5\times 10^5\).
Submissions
Please login to view your submissions
Similar Problems
Points:50
43 votes
Tags:
AlgorithmsData StructuresGraphsString ManipulationTries
Points:50
2 votes
Tags:
ArraysLCPMediumString ManipulationSuffix tree
Points:50
6 votes
Tags:
AlgorithmsString Manipulation
Editorial