This is a bit more difficult than it seems and the one other post on here isn't sufficient. You have a row of n items, and each item could be any one of 5 colors. You need to find if there are any runs of 3 or more items together of the same color and destroy them.
Yellow, Red, Blue, Green, Red, Red - destroy nothing
Red, Red, Red, Green, Yellow, Red - destroy the first set of 3 Red, but not the 6th red
Red, Purple, Red, Red, Red, Red - destroy only the set of 4 Red
You can't simply check each item to see if the item previous to it has the same color, and destroy them when that happens twice in a row (meaning 3 matching items), because then you are not accounting for the fact that there could be 4 or more in a row. Are there any robust algorithms out there for this?
