30:00
Given two strings s1 and s2, return the lowest ASCII sum of deleted characters needed to make the two strings equal.
1≤s1.length,s2.length≤10001 \leq \text{s1.length}, \text{s2.length} \leq 10001≤s1.length,s2.length≤1000
s1 and s2 consist of lowercase English letters.
s1
s2
Run code to see results.
Build an (4) x (4) table: dp[i][j] = cheapest ASCII total of deletions that makes the first i letters of s1 equal the first j letters of s2.
Every letter has a price: its ASCII code. Deleting it costs that much.
s
115
e
101
a
97
t
116
↘ equal letters: keep both, cost 0
↓ pay for the s1 letter
→ pay for the s2 letter
Delete characters from two strings until they are equal, paying each deleted character's ASCII code. Find the cheapest total.