18 ms·
It looks like collections is part of the standard library: http://docs.python.org/2/library/collections.html http://docs.python.org/2/library/collections.html.
by jkrems 13y ago
It looks like collections is part of the standard library: http://docs.python.org/2/library/collections.html http://docs.python.org/2/library/collections.html. I think this disqualifies your JS solution, as long as doStuff isn't some fancy nodejs core module I missed.
- untog 13y agoI think the point still stands though, when you think of it as an interview question. The point is to get to the bottom of how the candidate would process such a query themselves, not to test their knowledge of the core libraries of their favourite language. I feel like that's what the post author meant when he said that LINQ had "ruined" the question- because it kind of does the same thing.
- cben 13y agocollections.Counter.most_common() uses heapq.nlargest() which is slightly more efficient than a full n*log n sort. But implementing a heap correctly from scratch is I guess outside the scope the OP intends for the interview question. I would expect a good candidate to: 1. know that a heap is optimal here (remembering whether Counter uses it is optional) 2. express reluctance to implement it from scratch because surely the stdlib can do it better. So IMHO using libraries like this ruins the question only in the sense of showing its not a challenge for the candidate. Something so simple should not take a page of code.
- klipt 13y ago> collections.Counter.most_common() uses heapq.nlargest() which is slightly more efficient than a full n*log n sort. Creating a heap is O(n) if I remember correctly, so that may well be the most efficient solution.
- rhizome 13y agoIsn't it kind of axiomatic that any question that provides for a concise and measurable solution will eventually be refactored into a library? It seems like kind of a weakness in these kinds of "programmer" questions, that they all regress to trivia. Why not an open-ended business problem and/or deliverables-type question? I'm sure that would speak more to the daily job, where I've never heard of someone being tasked with "OK, find the top 10 words by frequency in a random Wikipedia article."
- untog 13y agoSurely the 'trivia' in this instance is knowing the names of libraries, as opposed to be able to think through programming concepts? Just like math homework back in the day, the teacher didn't do it to check your answer, they did it to check how you arrived at your answer.
- rhizome 13y agoMy memory of the math homework you describe brings up two images: geometry proofs and story problems. Never did I have to explain multiplication when doing my times tables, nor quadratics.
- CanSpice 13y ago"Sorry, we're stuck with Python 2.3.7 and collections isn't part of the standard library."
- wiredfool 13y ago"""Thank you, I think I've heard enough. I don't think continuing the interview would be a productive use of time."""
- kenko 13y agoBecause of an older version of python?!
- wiredfool 13y agoIf they're stuck on a version of software that hasn't been supported in 5 years for bugs or security with a set of features that was originally released nearly 10 years ago, it means that there are some culture issues in the workplace that will most likely drive me insane. Therefore, I am unlikely to take the job.
- pjmlp 13y agoMost companies are not startups, installing software as soon as new releases get available. Just to give another example, our consulting company still gets requests for projects to be deployed against Java 1.4!
- yen223 13y agoI like the fact that you triple-quoted that statement.