Minimum ASCII Delete Sum for Two Strings - Problem
Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.
When you delete a character from either string, you add its ASCII value to the total cost. Your goal is to find the minimum total cost needed to make both strings identical.
Note: The final equal strings can be any string that can be formed by deleting characters from both input strings.
Input & Output
Example 1 — Basic Case
$
Input:
s1 = "sea", s2 = "eat"
›
Output:
231
💡 Note:
Delete 's' from "sea" (ASCII 115) and 't' from "eat" (ASCII 116). Both become "ea". Total cost: 115 + 116 = 231.
Example 2 — One String Empty
$
Input:
s1 = "delete", s2 = ""
›
Output:
631
💡 Note:
Delete all characters from "delete": d(100) + e(101) + l(108) + e(101) + t(116) + e(101) = 631.
Example 3 — Identical Strings
$
Input:
s1 = "abc", s2 = "abc"
›
Output:
0
💡 Note:
Strings are already identical, no deletions needed. Cost = 0.
Constraints
- 1 ≤ s1.length, s2.length ≤ 1000
- s1 and s2 consist of lowercase English letters only
Visualization
Tap to expand
Understanding the Visualization
1
Input Strings
s1="sea" and s2="eat" with different characters
2
Find Common Parts
Identify shared subsequence "ea" to keep
3
Calculate Deletions
Delete 's'(115) + 't'(116) = 231 total cost
Key Takeaway
🎯 Key Insight: Keep the longest common subsequence, delete everything else with minimum ASCII cost
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code