Algorithms and Data Structures · Senior · Question 67 of 75

How do you check whether two words are one edit apart in O(n)?

Explanation

If lengths differ by more than one, the answer is no. Otherwise move pointers together and, at the first mismatch, skip a character in the longer word (or both for equal length). The full DP is O(n × m).

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 67

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz