One Edit Distance

Given two strings s and t, return true if they are exactly one edit apart. A single edit is an insertion, deletion, or replacement of one character. Pattern focus: Edit distance. This is the simplest non-trivial edit-distance variant and tests boundary handling carefully.

Input Format

s = first string, t = second string

Output Format

true if the strings are exactly one edit apart, otherwise false

Constraints

  • 0 <= s.length, t.length <= 10^5
  • s and t contain lowercase English letters.

Examples

Example 1:

Input:

s = "ab"
t = "acb"

Output:

true

Explanation:

Insert c into ab to get acb in exactly one edit.

Example 2:

Input:

s = "abc"
t = "abc"

Output:

false

Explanation:

Zero edits are not allowed.

Loading...
One Edit Distance - Dp Strings DSA Problem