Problem Link :Practice Contest
Levenshtein distance algorithm, Longest common subsequence
Given four strings, find minimum number of charater removal required to make all the
The problem is a standard dynamic programming problem. This can be solved using
Levenshtein distance algorithm, also known as Edit distance algorithm. For the given problem, we
had to extend the algorithm for four strings. See the setter solution 1 for implementation.
Since we are to make the strings equal only by removing certain elements, the resulting
strings must be equal to the longest common subsequence of the strings. So, finding the length of
the longest common subsequence is required which is also a standard dynamic programming
problem. After finding the length of the longest common subsequence, we can subtract it from the
lengths of the each strings. The difference is the number of characters removed from the string. The
sum of the results of the four subtractions is the required number of characters removed.
See the setter solution 2 for implementation.
N.B. If you can solve it using some other methods, please share in the comments.