#C5084. Reversible Substring Transformation
Reversible Substring Transformation
Reversible Substring Transformation
Given two strings S and T of equal length \(n\), determine whether S can be transformed into T by performing a series of operations. In each operation, you may reverse any non-empty substring of the string.
The reversal operation preserves the multiset of characters. In other words, the transformation is possible if and only if the sorted order of characters of S is equal to that of T, i.e., \(\text{sorted}(S)=\text{sorted}(T)\).
Output YES if such a transformation is possible, or NO otherwise.
inputFormat
The input consists of three lines:
- An integer (n) representing the length of the strings.
- A string (S) of length (n).
- A string (T) of length (n).
It is guaranteed that the lengths of (S) and (T) are equal.
outputFormat
Output a single line containing either "YES" if (S) can be transformed into (T) using the allowed operations, or "NO" otherwise.## sample
6
abcdef
fedcba
YES
</p>