<s>[INST] function editdistance(a: String, b: String): Integer {
    if a is empty {
        return b.length
    }
    if b is empty {
        return a.length
    }
    if a[0] == b[0] {
        return editdistance(a.substring(1), b.substring(1))
    } else {
        return 1 + min(editdistance(a.substring(1), b), editdistance(a, b.substring(1)), editdistance(a.substring(1), b.substring(1)))
    }
}

Can someone help me improve this recursive function so it doesn't have exponential time complexity?[/INST]