#K95692. Transformation by Reversing Subsegments
Transformation by Reversing Subsegments
Transformation by Reversing Subsegments
Given two strings s1 and s2, determine whether s1 can be transformed into s2 by reversing any number of continuous subsegments (possibly zero).
This operation is possible if and only if the two strings have the same multiset of characters (i.e., they are anagrams) and have identical lengths. In other words, you have to check whether the sorted order of the characters of both strings is the same.
Note: The reversal of subsegments can simulate any permutation if the character frequencies match.
inputFormat
The input consists of two lines: the first line contains the string s1, and the second line contains the string s2.
outputFormat
Print "YES" if s1 can be transformed into s2 by reversing subsegments, otherwise print "NO".## sample
abcdef
abcdef
YES