pyassistant

Minimum total deletions to make all strings equal (LCS across many strings)

Given a list of strings words, you may delete characters (anywhere) from any of the strings. What is the minimum total number of deletions required so that after deletions all strings become exactly the same string? Return that minimum total number of deletions. In other words, find a string t that is a subsequence of every word in words and that maximizes len(t). Let L be that maximum length (the length of a longest common subsequence across all input strings). The answer is sum(len(word) for word in words) - N * L. Constraints for this challenge: solve must work for moderate sizes (several short strings). Implement an algorithm that computes the longest common subsequence across all given strings and returns the minimum total deletions required to make all strings equal.

Example:

Input:
(["abcde","abfde","abcfde"])
Output:
6

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.