Facebook

  www.facebook.com
  www.facebook.com

Interview Question

Software Development Engineer Interview

Edit distance of words and distributed system questions.

Answer

Interview Answer

1 Answer

0

(edit distance of words)

public static int editDistance(String a, String b)
{
    if (null == a) return -1;
    if (null == b) return -1;
    if (a.equals("")) return b.length();
    if (b.equals("")) return a.length();
    int editDistance = a.length() + b.length();
    if (a.substring(0, 1).equals(b.substring(0, 1)))
    {
        editDistance = editDistance(a.substring(1, a.length()), b.substring(1, b.length()));
    }
    editDistance = Math.min(editDistance, 1 + editDistance(a, b.substring(1, b.length())));
    editDistance = Math.min(editDistance, 1 + editDistance(b, a.substring(1, a.length())));
    return editDistance;
}

Rahul on May 2, 2013

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up