Loading...
Loading...
A spell checker suggests a word only if it is exactly one edit away from what was typed. One edit is: insert one letter, delete one letter, or replace one letter. Read the typed word and the dictionary word and print YES if they are exactly one edit apart, and NO otherwise. Two equal words are zero edits apart, so the answer is NO.
YES or NO.Example 1
Input
pale ple
Output
YES
Delete a.
Example 2
Input
pale bake
Output
NO
Two letters differ.
Try the problem first. Open one hint at a time.
If the lengths differ by more than 1, the answer is NO at once.
Make sure the first word is the shorter one (swap if needed). Walk both until the first different position i.
Same length: the rest after i must be equal in both (a replace). Lengths differ by 1: the shorter from i must equal the longer from i + 1 (an insert).
If no difference is found, the words are one edit apart only when the longer one has one extra letter at the end.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor