Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-360

Normalized Levenshtein Similarity

Problem

The normalized Levenshtein similarity is 1 - distance / max(len(a), len(b)), with 1.0 when both strings are empty.

Given the two strings, return the similarity using the standard unit-cost edit distance.

Hint

Normalize the distance by the longer string length.

Test cases

case 1
in: ["cat","cot"]
expected: 0.6666666666666667
case 2
in: ["abc","abc"]
expected: 1
case 3
in: ["",""]
expected: 1
Starter codePython
def normalized_levenshtein_similarity(a, b):
    # Your code here
    pass

3 test cases · run your code against them in the editor