#C10987. Transforming Strings Through Substring Reversals
Transforming Strings Through Substring Reversals
Transforming Strings Through Substring Reversals
Given two strings (s_1) and (s_2), determine whether (s_1) can be transformed into (s_2) by reversing any number of substrings any number of times. A reversal operation inverts a contiguous segment of the string. It is known that by repeatedly reversing substrings, any permutation of the string is achievable. Hence, the transformation is possible if and only if (s_1) and (s_2) are anagrams; that is, they contain the same characters with the same frequencies. Mathematically, the condition is given by:
[ \text{multiset}(s_1) = \text{multiset}(s_2) ]
Print "YES" if the transformation is possible, otherwise print "NO".
inputFormat
The input consists of two lines from standard input. The first line contains the string (s_1), and the second line contains the string (s_2). Both strings will consist of lowercase letters only.
outputFormat
Output a single line to standard output containing "YES" if (s_1) can be transformed into (s_2) using a sequence of substring reversals; otherwise, output "NO".## sample
abc
bca
YES