Grokking LinkedIn Coding Interview
Ask Author
Back to course home

0% completed

Solution: Edit Distance

Problem Statement

Given two strings word1 and word2, return the least number of edits needed to transform word1 to word2.

You can perform any one edit from below three in a single operation on Word:

  • Insert a character
  • Delete a character
  • Replace a character

Examples

  • Example 1:

    • Input: word1 = "cat", word2 = "cut"
    • Expected Output: 1
    • Justification: Only one operation is needed, replacing 'a' with 'u' in "cat" to make it "cut".
  • Example 2:

    • Input: word1 = "sun", word2 = "satur"
    • Expected Output: 3

.....

.....

.....

Like the course? Get enrolled and start learning!