Hacker News new | ask | show | jobs
by kornakiewicz 4211 days ago
I remember story of my friend in algorithmic contest for high school students in Poland (which are quite hard). He solved problems correctly, but in his implementation he got to check in every iteration of loop if a collection still got any elements. He used col.size()==0 instead of col.isEmpty(). The first was O(n) and it fucked up all performance.
1 comments

That's a bug.
Not really, some containers have a linear-time size by design. The canonical example is a linked list in which you wish to keep the splice-another-list-at-middle time linear.