#K58162. One-Edit Transformation
One-Edit Transformation
One-Edit Transformation
Given two strings \(s_1\) and \(s_2\), determine whether \(s_1\) can be transformed into \(s_2\) with at most one modification. A modification is defined as an insertion, deletion, or substitution of a single character.
Formally, the following conditions must be satisfied:
- \(\left| |s_1| - |s_2| \right| \le 1\)
- At most one edit (insertion, deletion, or substitution) is needed to transform \(s_1\) into \(s_2\).
If these conditions are met, output Yes
; otherwise, output No
.
inputFormat
The first line contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains two space-separated strings \(s_1\) and \(s_2\).
outputFormat
For each test case, print a single line containing either Yes
if \(s_1\) can be transformed into \(s_2\) with at most one modification, or No
otherwise.
4
pale ple
pales pale
pale bale
pale bake
Yes
Yes
Yes
No
</p>