Edit Distance (Levenshtein)

medium
Unit 3 · Heaps0/3 to milestone

The edit distance between two strings is the minimum number of single-character insertions, deletions or substitutions needed to turn one into the other. For example, kitten → sitting takes 3.

Implement edit_distance(a, b) with dynamic programming in O(len(a)⋅len(b))O(len(a) \cdot len(b)) time. Then implement word_error_rate(reference, hypothesis): the edit distance between the two word lists (split on whitespace), divided by the number of reference words. Return 0.0 if both are empty, and float("inf") if only the reference is empty.

#dynamic-programming#strings2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Edit Distance (Levenshtein) · TechGradify