Please, now that I have rewritten this question, and before it receives further answers of a quick answer or a premature closure by impatient editors, let me point out that this is not a duplicate of this question . I know how to remove duplicates from an array.
This question is about removing sequences from an array, not duplication in the strict sense.
Consider this sequence of elements in an array;
[0] a [1] a [2] b [3] c [4] c [5] a [6] c [7] d [8] c [9] d
In this example, I want to get the following ...
[0] a [1] b [2] c [3] a [4] c [5] d
Note that duplicate elements are preserved, but sequences of the same element are reduced to one instance of this element.
In addition, note that when repeating two lines, they should be reduced to one set (of two lines).
[0] c [1] d [2] c [3] d
... comes down to ...
[0] c [1] d
I code in C #, but algorithms in any language are evaluated.
Ed guiness
source share