Create a function that calculates the Levenshtein distance (edit distance) between two strings.
HardProblem Statement
Create a function that calculates the Levenshtein distance (edit distance) between two strings.
Sample Input
"kitten", "sitting"
Sample Output
3
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Calculate the Levenshtein distance between two strings
function levenshteinDistance(str1, str2) {
// Initialize a 2D array for dynamic programming
// Update the array based on character insertions, deletions, or replacements
}
console.log(levenshteinDistance("kitten", "sitting"));
Input
"kitten", "sitting"
Expected Output
3