Under construction

Still being built. Things may change

Minimum edit

Interview

Time limit2sMemory limit512 MB

Summary
Compute the Levenshtein distance between two lowercase strings, using the fewest insert, delete, and replace operations to change A into B.
Level

Medium6 of 10

Topics
Dynamic programming, String, Array, Prefix sum
Solved
No attempts yet

Problem

Given two strings AA and BB, the task of turning AA into BB with the fewest operations is called the minimum edit problem.

Three operations apply to AA.

  1. Insert: put one character at any position of AA.
  2. Delete: remove one character of AA.
  3. Replace: change one character of AA into another character.

Given the two strings, write a program that computes the minimum number of edits.

Input

The first line has the string AA and the second line has the string BB. Both strings consist of lowercase letters only, and neither is longer than 1000 characters.

Output

Print on the first line the minimum number of edits that turn AA into BB.

Examples10

  1. Example 1

    Input
    abc
    ab
    
    Expected output
    1
    
  2. Example 2

    Input
    ca
    abc
    
    Expected output
    3
    
  3. Example 3

    Input
    abc
    cba
    
    Expected output
    2
    
  4. Example 4

    Input
    abcd
    bcde
    
    Expected output
    2
    
  5. Example 5

    Input
    abababababa
    aaaaaaaaaaa
    
    Expected output
    5
    
  6. Example 6

    Input
    for
    whileforif
    
    Expected output
    7
    
  7. Example 7

    Input
    whilewhile
    whalewhale
    
    Expected output
    2
    
  8. Example 8

    Input
    aaabaaa
    acacaca
    
    Expected output
    3
    
  9. Example 9

    Input
    qwerty
    dvorak
    
    Expected output
    5
    
  10. Example 10

    Input
    asdf
    asdf
    
    Expected output
    0