Say I have two lists or arrays of strings. For example:
list 1: “a”, “c”, “b”, “d”, “f”, “e”
list 2: “a”, “d”, “e”, “f”, “h”
List 1 and list 2 are of arbitrary lengths. List 1 may contain elements not in list 2, and visa versa.
I’d like to know when items in list 1 are found in list 2, and more specifically I want to know when an item in list 1 is found in list 2 but is found in a different order than which it is found in list 2, relative to the items in list 2. (Hopefully the example below clarifies this statement).
For example, “a” is found in both lists and is the first item in both lists. So, everything is okay so far. “c” and “b” are found in only the 1st list and so can be ignored. “h” is found in only the 2nd list and can also therefore be ignored.
“d” is found in both the 1st and 2nd list. It is found after “a” (the first item) in the original list. Even though the position within the 1st list is different form the second list, it is is okay because its relative order is the same within the two lists (the second match in common between lists).
In the example above “f” and “e” are in the ‘wrong’ order in list 1, because “e” comes becomes before “f” in the 2nd list. So, I would like to report that “e” and “f” are in the wrong order in the first list. How would I do this?
The solution should be in C#. Thank you!
result
position 2 is item [f] on list1 but its [e] in list2
position 3 is item [e] on list1 but its [f] in list2