check 6 indices below last deepest removal 00000000001111111111222222222 01234567890123456789012345678 compare from 27 to 22 with 28 b6948173ba042635b08917b423812 ~~~~~~~~~~~~~~~~~~~~~~ ^* OK b6948173ba042635b08917b423812 ~~~~~~~~~~~~~~~~~~~~~~ ^ * OK b6948173ba042635b08917b423812 ~~~~~~~~~~~~~~~~~~~~~~ ^ * OK b6948173ba042635b08917b423812 ~~~~~~~~~~~~~~~~~~~~~~ ^ * REMOVE b6948173ba042635b08917b43812 ~~~~~~~~~~~~~~~~~~ ^ * 00000000001111111111222222222 01234567890123456789012345678 b6948173ba042635b08917b423812 b6948173ba042635b08917b4_3812 b6948173ba042635b089_7b4_3812 b6948173ba042635b0_9_7b4_3812 b6948173ba042635_0_9_7b4_3812 b6948173ba_42635_0_9_7b4_3812 b694817_ba_42635_0_9_7b4_3812 b69_817_ba_42635_0_9_7b4_3812 _69_817_ba_42635_0_9_7b4_3812 69817ba42635097b43812 b6948173ba042635097b43812 00000000001111111111222222222 01234567890123456789012345678 b6948173ba042635b08917b423812 0 17, 10 1 20, 5 2 12 3 14, 7 4 11, 3 5 15 6 13, 1 7 21, 6 8 18, 4 9 19, 2 a 9 b 22, 16, 8, 0 0000000000111111111122222222223333 0123456789012345678901234567890123 6666666666666666666666666666666660 b6948173ba04263915b0874923187b4238 ^^ compare [33] <-> [32] OK 6666666666666666666666666666666661 b6948173ba04263915b0874923187b4238 ^ ^ compare [33] <-> [31] OK 6666666666666666666666666666666662 b6948173ba04263915b0874923187b4238 ^ ^ compare [33] <-> [30] OK 6666666666666666666666666666666663 b6948173ba04263915b0874923187b4238 ^ ^ compare [33] <-> [29] OK 6666666666666666666666666666666664 b6948173ba04263915b0874923187b4238 ^ ^ compare [33] <-> [28] OK 6666666666666666666666666666666665 b6948173ba04263915b0874923187b4238 ^ ^ compare [33] <-> [27] ERROR, DELETE [27] 666666666666666666666666666_555555 b6948173ba04263915b08749231_7b4238 ^ ^ compare [33] <-> [26] OK 666666666666666666666666666_555556 b6948173ba04263915b08749231_7b4238 ^ ^ compare [32] <-> [25] ERROR, DELETE [25] 6666666666666666666666666_5_444456 b6948173ba04263915b087492_1_7b4238 ^ ^ compare [32] <-> [24] OK 6666666666666666666666666_5_444466 b6948173ba04263915b087492_1_7b4238 ^ ^ compare [31] <-> [24] ERROR, DELETE [24] 666666666666666666666666__4_333456 b6948173ba04263915b08749__1_7b4238 ^ ^ compare [32] <-> [23] OK 666666666666666666666666__4_333466 b6948173ba04263915b08749__1_7b4238 ^ ^ compare [31] <-> [23] OK 666666666666666666666666__4_333566 b6948173ba04263915b08749__1_7b4238 ^ ^ compare [31] <-> [22] OK 666666666666666666666666__4_333666 b6948173ba04263915b08749__1_7b4238 ^ ^ compare [30] <-> [23] OK 666666666666666666666666__4_334666 b6948173ba04263915b08749__1_7b4238 ^ ^ compare [30] <-> [22] ERROR, DELETE [22] 6666666666666666666666_5__3_234566 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [31] <-> [21] OK 6666666666666666666666_5__3_234666 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [30] <-> [21] OK 6666666666666666666666_5__3_235666 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [30] <-> [20] OK 6666666666666666666666_5__3_236666 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [29] <-> [21] OK 6666666666666666666666_5__3_246666 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [29] <-> [20] OK 6666666666666666666666_5__3_256666 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [29] <-> [19] OK 6666666666666666666666_5__3_266666 b6948173ba04263915b087_9__1_7b4238 ^ ^ compare [28] <-> [21] ERROR, REMOVE [21] 666666666666666666666__4__2_256666 b6948173ba04263915b08__9__1_7b4238 _69_817_ba_4263__5_08__9__1_7b4238 0000000000111111111122222222223333 0123456789012345678901234567890123 algorithm: start condition: have a distance to next same value and index of same value stored at every value (also optionally have a table with the index of last occurrance and a count) add new value to the right check distance from right to left if distance <= 6, remove offending index and update affected counts (affected or not can be read from the index) example: 8 is added to the right highest_affected=33, lowest_affected=33 --------0--0-0000-0100111112212222 --------0--3-1725-8046152460182457 --------8--8-c7db-a9gfb8cba77b8776 b6948173ba04263915b0874923187b4238 we see that the distance is 6, this is not enough so remove previous 8 and update distances highest_affected=33, lowest_affected=28 --------0--0-0000-010011111 212222 --------0--3-1725-804615246 182450 --------8--8-c7db-a9gfb8cba 6a766c b6948173ba04263915b08749231_7b4238 now position 33 is ok, but 32 fails, so highest_affected=33, lowest_affected=28 --------0--0-0000-0100111 1 212212 --------0--3-1725-8046152 6 182440 --------8--8-c7db-a9gfb8c 9 5965gb b6948173ba04263915b0874923187b4238 now position 32 is ok, but 31 fails highest_affected=33, lowest_affected=26 --------0--0-0000-010011 1 212112 --------0--3-1725-804615 6 182240 --------8--8-c7db-a9gfb8 8 485gfa b6948173ba04263915b0874923187b4238 position 31 is ok, but 30 fails highest_affected=33, lowest_affected=26 --------0--0-0000-0100 1 1 211112 --------0--3-1725-8046 5 6 181240 --------8--8-c7db-a9gf 7 7 48ggfa b6948173ba04263915b0874923187b4238 _69_817_ba_4263__5_08__9__1_7b4238