A simple clustering algorithm for lists
cassidoo.co
cassidoo.co
Also, she doesn't really need to keep all consecutive items of the same color, only the number of them, so she could merge consecutive items of same color and add their multiplicities.
At least it's not O(n³).
For instance, I found insertion sort to be the most effective at sorting papers when I was grading. . . at least, as long as the students bothered writing their names on their homework.
Glancing at the code it has three nested loops (two "while"s, and one "reverse" call), which makes it O(N^3) before optimizations.