#K69217. One Operation String Transformation
One Operation String Transformation
One Operation String Transformation
You are given two strings s1 and s2. Your task is to determine whether it is possible to transform s1 into s2 by performing exactly one of the following operations:
- Insert exactly one character at any position in the string.
- Remove exactly one character from any position in the string.
- Replace exactly one character in the string with a different character.
In mathematical terms, let \(n = |s_1|\) and \(m = |s_2|\). Then the allowed operations are only valid if either:
- \(n = m\) and exactly one character differs between \(s_1\) and \(s_2\) (replacement), or
- \(n + 1 = m\) (insertion), or
- \(n - 1 = m\) (removal).
Note that if no operation or more than one operation is needed, the answer is False
.
Input/Output: The program reads the input from stdin
and writes the result to stdout
.
Example:
Input: abc ab</p>Output: True
inputFormat
The input consists of two lines. The first line is the string s1 and the second line is the string s2.
outputFormat
Output a single line: True
if s1 can be transformed into s2 with exactly one allowed operation, otherwise output False
.
abc
ab
True