If I have a list like this
my_list = [1, 7, 3, 4, 2, 9, 6, 5, 8]
Also I have other lists of length less than the length of my_list
. For instance, let us say I have two other lists as follows:
my_other_list_1 = [1, 7, 3, 4, 2]
my_other_list_2 = [1, 7, 4, 9, 8]
All lists have distinct elements and the other lists have elements from the original list.
My problem is to find the list (either my_other_list_1
or my_other_list_2
) that has the longest match in my_list
. First, I would like to ask what is this problem called? Then, I prefer to get the length of the longest match of each list. How do I do this?
In the example, I would return my_other_list_1
because it has a match of length 5
since [1, 7, 3, 4, 2]
is already in my_list
. Also, I would return 2
for my_other_list_2
because there is a match of length 2
in it, i.e., [1, 7]
.
Summarizing, if I have an algorithm A and the inputs are my_list
, my_other_list_1
and my_other_list_2
, the algorithm should return
my_other_list_1 has match 5
my_other_list_2 has match 2
NB. I think this is a problem called longest common subsequences (LCS) problem but as I understand in LCS problem the subsequences do not need to be consecutive.