Remix.run Logo
emil-lp 2 days ago

Since she doesn't use anything clever to find the index of the rightmost-not-at-end, she could use doubly-linked list which would give O(1) reversal of sublist.

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³).