Google | On-site | Smallest Edit Distance to Convert Path
Anonymous User
3505

You are given a path where each node is represented by a string (e.g, "abc" -> "de" -> "xyz"). Also you are given the nodes (represented by strings as well) and undirected edges of a graph. Your task is to covert the given path to any path available in the graph with minimal edit distance, The edit distance between two strings is the number of operations need to add/.delete/replace on one string to convert to another string (for example, "abc" to "abd", distance is 1).

Example:

Given path:  "abc" -> "de" -> "xyz"
Given graph: ["ab", "x"], ["abc", "d"], ["de", "xyz"], ["pqr", "de"], ["d", "xy"], here [u, v] means there is an edge between u and v
Ans: 2. You can change "de" to "d" and "xyz" to "xy"
Comments (8)