Problem 93. Calculate the Levenshtein distance between two strings

Created by Cody Team in Community

This problem description is lifted from

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'


 s2 = 'sitting'

then the distance d is equal to 3.

Solution Stats

53.15% Correct | 46.85% Incorrect
Last solution submitted on Mar 15, 2019

Problem Comments

Solution Comments

Recent Solvers278

Suggested Problems

More from this Author95

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!