Two notes are stored as strings of lowercase letters. Each letter has a weight equal to its position in the alphabet: a = 1, b = 2, ..., z = 26. You may delete characters from either string; deleting a character costs its weight. Find the minimum total weight of deleted characters needed to make the two strings equal.
Line 1: the first note string a.
Line 2: the second note string b.
A single integer: the minimum total weight of deleted characters.
a <= 40b <= 40Example 1
Input
sea eat
Expected
39
Explanation
Delete s (weight 19) from sea and t (weight 20) from eat, leaving ea in both; total deleted weight is 39, the minimum.
Example 2
Input
abc bcd
Expected
5
Explanation
Delete a (weight 1) from abc and d (weight 4) from bcd, leaving bc in both; total 5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →