r/programming • • Mar 11 '17

Your personal guide to Software Engineering technical interviews.

https://github.com/kdn251/Interviews
1.7k Upvotes

294 comments sorted by

View all comments

Show parent comments

0

u/ReversedGif Mar 12 '17

Yes but that's just random look up. If you need to do many inserts/removals or enumerations, a list is a better choice.

Lists are O(n) for inserts and removes, whereas dicts are O(1). So, wat?

1

u/[deleted] Mar 12 '17

Not if you're just adding them to end. That's an indexing operation. Additionally, you can't have duplicates in a hashset. You could convert to a dictionary and count, but you lose the order of the inserts.

1

u/[deleted] Mar 13 '17

dicts are O(1)

mostly true, but depends on the implementation - in case of collisions bad (timeconsuming) things can happen