Determine a one-step string transformation
Problem Description
Given two lowercase strings, source and target, determine if target can be obtained from source by applying at most one of the specified operations. If a transformation is possible, output one valid operation. If source is already identical to target, output no_change. If no single operation can transform source into target, output impossible. If multiple valid operations exist, any one valid operation is acceptable.
Allowed Operations
add c: Insert one charactercat any position insource.delete c: Delete one occurrence of charactercfromsource.replace x y: Replace one occurrence of characterxinsourcewith charactery.move c: Remove one occurrence of charactercfrom its current position and insert it at another position in the string.
Examples
source = "baren", target = "bbren"
output: replace a b
source = "banan", target = "banana"
output: add a
source = "abcde", target = "acdeb"
output: move b
Constraints & Follow-up
Design an efficient solution that handles long strings, ideally in linear time complexity.
AI interview prep
Core dilemma
Efficiently and unambiguously identifying if *exactly one* of four distinct string transformation operations (add, delete, replace, move) can convert a source string to a target string, especially when some operations can mimic others, all while adhering to linear time complexity.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Determine a one-step string transformation
Problem Description
Given two lowercase strings, source and target, determine if target can be obtained from source by applying at most one of the specified operations. If a transformation is possible, output one valid operation. If source is already identical to target, output no_change. If no single operation can transform source into target, output impossible. If multiple valid operations exist, any one valid operation is acceptable.
Allowed Operations
add c: Insert one charactercat any position insource.delete c: Delete one occurrence of charactercfromsource.replace x y: Replace one occurrence of characterxinsourcewith charactery.move c: Remove one occurrence of charactercfrom its current position and insert it at another position in the string.
Examples
source = "baren", target = "bbren"
output: replace a b
source = "banan", target = "banana"
output: add a
source = "abcde", target = "acdeb"
output: move b
Constraints & Follow-up
Design an efficient solution that handles long strings, ideally in linear time complexity.