Minimum ASCII Delete Sum for Two Strings

Given two strings s1 and s2, return the minimum sum of ASCII values of characters that must be deleted from the two strings so that they become equal. Pattern focus: Edit distance. This is a weighted string DP variant where deletion cost depends on character values.

Input Format

s1 = first string, s2 = second string

Output Format

minimum ASCII delete sum

Constraints

  • 0 <= s1.length, s2.length <= 1000
  • s1 and s2 contain lowercase English letters.

Examples

Example 1:

Input:

s1 = "sea"
s2 = "eat"

Output:

231

Explanation:

Delete 's' from sea and 't' from eat, total 115 + 116 = 231.

Example 2:

Input:

s1 = "a"
s2 = "b"

Output:

195

Explanation:

Delete both characters: 97 + 98 = 195.

Loading...
Minimum ASCII Delete Sum for Two Strings