#C6407. Reversing Substring Equality
Reversing Substring Equality
Reversing Substring Equality
You are given two strings s and t of equal length. Your task is to determine whether it is possible to obtain t from s by reversing exactly one continuous substring of s. Reversing a substring means taking a continuous segment of characters in s and reversing their order. If the strings are already equal, the answer should be YES
.
Formal Statement:
Given two strings \( s \) and \( t \) of equal length \( n \), check if there exist indices \( 0 \leq L < R \leq n-1 \) such that if you reverse the substring \( s[L...R] \) then \( s \) becomes identical to \( t \). If \( s = t \), output YES
.
It is guaranteed that the input strings consist of lowercase English letters and have the same length.
inputFormat
The input consists of two lines. The first line contains the string s. The second line contains the string t.
outputFormat
Output a single line containing YES
if it is possible to make s equal to t by reversing exactly one continuous substring of s, otherwise print NO
.
abcdef
abcfed
YES
</p>