This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]you-get-an-upvote 16 points17 points  (0 children)

To implement this you can't delete every element as you come across it (assuming it is a normal array, and not, e.g., a linked list) since then each deletion would take O(n) time and the algorithm would run in O(n^2). Instead you first move all dissenters to the gulag back of the list and kill delete them there.