#C3757. Adjacent Swap Transformation
Adjacent Swap Transformation
Adjacent Swap Transformation
You are given two strings \(s_1\) and \(s_2\). Your task is to determine whether \(s_1\) can be transformed into \(s_2\) by performing a series of swap operations on adjacent characters. In other words, you are allowed to swap any two adjacent characters any number of times. The transformation is possible if and only if the two strings have the same multiset of characters. For example, if \(s_1 = \texttt{abccba}\) and \(s_2 = \texttt{baccab}\), then the answer is Yes, because the character frequencies match. Otherwise, if the frequencies differ, the answer is No.
inputFormat
The input consists of two lines. The first line contains the string \(s_1\). The second line contains the string \(s_2\). Both strings will consist of lowercase or uppercase English letters and possibly other characters.
outputFormat
Output a single line containing either Yes
if \(s_1\) can be transformed into \(s_2\) using adjacent swaps, or No
otherwise.
abccba
baccab
Yes