Oracle | Phone | Diff Generator
Anonymous User
1092

Given two strings source and target, return a list of minimum edits required to convert source to target.
An edit is removal from source or addition to target or the common character if the characters are equal. In case of multiple answers, prefer removing from source.

  • When removing a character from source to get to target , append it with '-'.
  • When adding a character to get to target , append it with '+'.
  • When characters are same, add it as it is.

For example, source = "pop", and target = "tops"
ans: [+t, -p, o, p, +s]

When reading the result list left to right, excluding removal edits i.e. those prefixed with a minus-sign, the edits should spell out target (ignoring +)
like, t (ignore -p) o p s, spells target string.

Comments (3)