Edit Distance
Given nonempty strings start and target, return the minimum number of unit-cost operations needed to transform start into target. One operation inserts one…
Given nonempty strings start and target, return the minimum number of unit-cost operations needed to transform start into target. One operation inserts one Unicode scalar at any position, deletes one scalar, or replaces one scalar with another. Return only the operation count; transposition is not a single operation. Characters are Unicode scalar values, not UTF-8 bytes, UTF-16 code units or visual grapheme clusters. Combining marks count separately. Do not normalize, case-fold, trim or ignore any scalar. Unpaired surrogates are outside the input domain.
- 1 <= scalar length of each operand <= 1000. - All Unicode scalar values are allowed; no unpaired surrogates. - The visualizer accepts each operand up to 8 scalars; longer valid inputs are coding-only.
Example 1: input start = "planet", target = "plan"; output 2. Delete e to obtain plant, then delete the final t to obtain plan: two deletions.
Example 2: input start = "abcdefg", target = "azced"; output 4. Replace b with z, delete d, delete f, and replace g with d: azcdefg → azcefg → azceg → azced.
Example 3: input start = "a", target = "b"; output 1. One replacement suffices; unlike insertion/deletion-only conversion, it costs one operation.
Category: Strings. Topic: dynamic-programming. Difficulty: hard. Patterns: dynamic-programming.