Sort both lists. Then you can know with confidence that if the next entry in list A is "cobble" and the next entry in list B is "defined", then "cobble" is not in list B. Just move the pointer / counter so that the list has more low ranked result and climb the ranking.
For instance:
List 1: D, B, M, A, I
List 2: I, A, P, N, D, G
sorted by:
List 1: A, B, D, I, M
List 2: A, D, G, I, N, P
A vs A → match, store A, advancing as
B vs D → B D vs D → match, store D, advance both
I am against G → I> G, moving forward 2
I vs i → match, store I, promoting how
M vs N → M List 1 has no more items, drop it.
List of matches: A, D, I
2 sorts the list O (n log (n)), and O (n) comparisons do this O (n (log (n) + 1)).
source share