Oracle | Phone | Diff Generator

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-06-27Added By Anonymous
Source: Link

Company: Oracle
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

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