I have two lists with same items and different orders.
for example:
a = [4, 2, 3, 1]
b = [2, 3, 1, 4]
Which item(s) should I remove to make lists same?
Here: [4] is an answer, so:
a = [2, 3, 1]
b = [2, 3, 1]
But [2, 4] or [2, 3, 1] are also answers, if I remove [2, 3, 1]:
a = [4]
b = [4]
I need to remove the minimum number of elements, here [4] is the optimal solution.
Another example:
a = [1, 2, 3, 4]
b = [2, 1, 4, 3]
Possible answers:
[1, 3]
[1, 4]
[2, 3]
[2, 4]
Order of algorithm is unimportant.
I would certainly search for the longest common subsequence first (google LCS, many algorithms are available, e.g. on algorithmist), then if you remove the LCS elements from one of the original list you got the shortest list of elements to remove. In pseudocode :