Calculate the Levenshtein distance between two strings - MATLAB Cody - MATLAB Central

Problem 93. Calculate the Levenshtein distance between two strings

Difficulty:Rate
This problem description is lifted from http://en.wikipedia.org/wiki/Levenshtein_distance.
The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.
For example, the Levenshtein distance between "kitten" and "sitting" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:
kitten => sitten (substitution of 's' for 'k')
sitten => sittin (substitution of 'e' for 'i')
sittin => sitting (insert 'g' at the end).
So when
s1 = 'kitten'
and
s2 = 'sitting'
then the distance d is equal to 3.

Solution Stats

63.89% Correct | 36.11% Incorrect
Last Solution submitted on Mar 24, 2025

Problem Comments

Solution Comments

Show comments
Who Deserves Your Praise? Discover the New Contribution Widget!
...
We are excited to announce another update to our Discussions area: the...

Problem Recent Solvers1455

Suggested Problems

More from this Author96

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page