You are given two strings s and t of lowercase letters. They are one edit apart when you can turn s into t using exactly one of the following operations:
Two identical strings are NOT one edit apart (that would take zero edits).
Line 1: the string s (possibly empty).
Line 2: the string t (possibly empty).
Print YES if s and t are exactly one edit apart, otherwise print NO.
a-z.Example 1
Input
cat cot
Expected
YES
Explanation
Replacing the single letter 'a' with 'o' turns cat into cot: exactly one edit, so YES.
Example 2
Input
cat cat
Expected
NO
Explanation
The strings are already identical, which needs zero edits, not one, so NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →