Work in HR? Unlock Free Profile

Facebook Software Development Engineer Interview Question

"Edit distance of words and distributed system questions."
Add Tags [?]

Part of a Software Development Engineer Interview Review - one of 1,090 Facebook Interview Reviews

Answers & Comments

of 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

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

Tags are like keywords that help categorize interview questions that have something in common.