You have to start with the last element and not the first one, that's for sure. Otherwise probably your iterators/indexes on both containers will go out of sync.
No, you can't get better than O(n) here - you have to check each element (so it's actually omega(n) and theta(n)).Furthermore: isn't "remove_if" above faster than your suggestion?
Bookmarks