Minimum ASCII Delete Sum for Two Strings

Medium

Description

Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.

Examples

Input:s1 = "sea", s2 = "eat"
Output:231
Explanation:

Delete 's' (115) and 't' (116) = 231.

Input:s1 = "a", s2 = "a"
Output:0
Explanation:

Edge case with a single character.

Input:s1 = "delete", s2 = "leet"
Output:403
Explanation:

To make both strings equal, delete characters not in the longest common subsequence. The sum of ASCII values of deleted characters is minimized by keeping the maximum-value common subsequence. The minimum deletion cost is the result.

Constraints

  • 1 ≤ s1.length, s2.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!