This question is about removing sequences from an array, not duplicates 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 obtain the following…
[0] a [1] b [2] c [3] a [4] c [5] d
Notice that duplicate elements are retained but that sequences of the same element have been reduced to a single instance of that element.
Further, notice that when two lines repeat they should be reduced to one set (of two lines).
[0] c [1] d [2] c [3] d
…reduces to…
[0] c [1] d
I’m coding in C# but algorithms in any language appreciated.
Here’s C# app i wrote that solves this problem.
takes
aabccacdcd
outputs
abcacd
Probably looks pretty messy, took me a bit to get my head around the dynamic pattern length bit.
fixed the initial values to match the questions values