Problem 339
One Edit Away
Medium · 20 pts · String, Two Pointers
Problem
There are three kinds of edits on a string: insert one character, delete one character, or replace one character with another. Given two strings, decide whether they are at most one edit apart. Two equal strings need zero edits, which also counts as YES. Strings whose lengths differ by two or more can never be one edit apart.
Input
Two lines: strings A and B of lowercase letters.
Output
Print YES if the strings are zero or one edit apart, otherwise NO.
Constraints
1 <= |A|, |B| <= 100000
Example input
pale ple
Example output
YES
Explanation
Deleting the 'a' from 'pale' gives 'ple', so the two strings are exactly one edit apart and the answer is YES.