32. One Edit Distance
Given two strings s0 and s1 determine whether they are one or zero edit distance away. An edit can be described as deleting a character, adding a character, or replacing a character with another character.
Constraints
n ≤ 100,000wherenis the length ofs0.m ≤ 100,000wheremis the length ofs1.
Example 1
s0 = "quicksort"
s1 = "quicksort"
Output
trueExplanation
This has the edit distance of 0, since they are the same string.
Example 2
s0 = "mergesort"
s1 = "mergesorts"
Output
trueExplanation
This has the edit distance 1, since s was added to the second string.
Example 3
Explanation
This has edit distance of 2.
Solution: (Without DP)
Time Complexity: O(n)
Last updated
Was this helpful?