#K83227. One-Swap Transformation
One-Swap Transformation
One-Swap Transformation
Given two strings \(S\) and \(T\), determine if string \(S\) can be transformed into string \(T\) by swapping exactly one pair of characters in \(S\). Formally, find if there exist two distinct indices \(i\) and \(j\) such that by swapping \(S_i\) and \(S_j\), we obtain \(T\). Note that the swap must be performed exactly once. If \(S\) has a different length than \(T\), the answer is NO
.
Input Constraints: \(1 \leq |S| = |T| \leq 10^5\) for valid cases.
Example:
Input: abcd abdc</p>Output: YES
inputFormat
The input consists of two lines. The first line contains the string \(S\) and the second line contains the string \(T\).
outputFormat
Output a single line containing either YES
if \(S\) can be transformed into \(T\) by swapping exactly one pair of characters, or NO
otherwise.
abcd
abdc
YES