Two bookkeeping ledgers are stored as strings of lowercase letters. In one cleanup step you may delete a single character from either string. Find the minimum total number of deletions needed to make the two strings identical.
Line 1: the first ledger string a.
Line 2: the second ledger string b.
A single integer: the minimum number of deletions required.
a <= 40b <= 40Example 1
Input
sea eat
Expected
2
Explanation
Delete s from sea and t from eat, leaving ea in both. That is 2 deletions, and no fewer works.
Example 2
Input
notebook note
Expected
4
Explanation
The longest common subsequence of the two words is "note" (length 4). Deleting the 4 characters "book" from the first word leaves "note", matching the second word, so 4 deletions are needed.
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 →