3 ms·
I'm surprised no one has brought up testing, or am I just too obsessed with testing? I'd argue you should have good test coverage and a well thought out API su
by city41 14y ago
I'm surprised no one has brought up testing, or am I just too obsessed with testing?
I'd argue you should have good test coverage and a well thought out API such that you can easily swap out the searching algorithm as needed to meet your needs without worries of breaking the component or things that depend on it. What if the function is handed a pointer to the array, and the caller doesn't want the data sorted?
Beyond that, I'd strongly argue the answer is: whatever can get me the answer with the most readable and simplest code. If this part of the program later proves to be a bottleneck, then consider different algorithms. Which again, good test coverage plays a roll in.
- raylu 14y agoWhat does any of that have to do with the question? This is a performance question. I'll accept readability/simplicity as an afterthought, but if you answer in this manner you've missed the (quite clear) point of the question.
- city41 14y agoI disagree the point of the question is clear. I also strongly argue that questions like this are not productive and that most companies have completely broken dev interviews. I disagree because I've been in interviews where a question like this, and all questions asked for that matter, have a testing expectation to them. If a developer answers this question without considering test coverage and what that means, some companies see that as a sign of a dev who doesn't appreciate tests or have a full grasp of the entire lifecycle of development. "Trick questions" with hidden undertones are very common. Or is it a practicality question? I do not want to hire a dev who is concerned with squeezing every drop of performance out of function calls that make up 0.001% of the app's runtime. Is finding out the candidate is aware that sort+binary search is O(nlogn) versus O(n) of linear search really enabling you to find a quality candidate? Maybe, but probably not. We don't ask questions like this at all anymore. The bulk of our interview process is sitting down with the candidate and writing a small program with them, end to end. Not perfect either, but far more effective than ambiguous questions.
- LockeWatts 14y agoYes you are. You didn't answer the question asked, you avoided the question and talked about what you found important, rather than what the interviewer found important.
- city41 14y agoSee my reply to raylu. I suppose I'm biased because I feel questions like this are completely ineffective. Whatever the interviewer finds to be important is not necessarily going to get them quality candidates.
- LockeWatts 14y agoBut that's for them to decide. You as the candidate have one directive, and an interrupt. If you want the job, do whatever it is you think you will impress the employer, unless whatever that would take convinces you you don't want the job.