Discover MakerZone

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

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!

Problem 848. Calculate a modified Levenshtein distance between two strings

Created by Matt Eicholtz

Inspired by the Cody problem found here.

The Levenshtein distance is a charater-based string metric used to measure the difference between two strings (for details, look here). In this problem, you need to implement a word-based version of the Levenshtein distance.

Given two strings, compute the minimum number of word-edits to transform one string into another. The allowable edits are insertion, deletion, or substitution of a single word. Assume words are case-insensitive. Contractions and hyphenated words are allowed, but you may ignore other punctuation.



s1 = 'I do not like MATLAB'
s2 = 'I love MATLAB a lot'


d = 4

because at least four edits are required to transform s1 into s2 (substitution on the last four words).

Problem Group

Solution Statistics

14 correct solutions 13 incorrect solutions
Last solution submitted on Mar 12, 2016

Problem Comments

Solution Comments