Live data from Hacker News

Life, the Universe and Technical Interviews

diegobasch.com

1–10 of 15 posts

Re: Life, the Universe and Technical Interviews

#3
I tend to ask what I think is a rather simpler question in most interviews: find the sum of the two largest (most positive) numbers in an array of arbitrary integers. Consider the efficiency of your solution for very large arrays.

It is amazing how many seemingly knowledgeable, intelligent people cannot do this. And the vast majority of those who do, do it by sorting the array, efficiency be damned.

Actually, I'd like a bit of feedback here. Is this something any decent developer should be able to do with ease? Should it be obvious that it can be done much more efficiently without running a sort on the array? Admittedly there are minor gotchas with things like the initial conditions, but still, I've been flabbergasted by how few people can even get close to a solution, let alone a bug-free and efficient one.

Re: Life, the Universe and Technical Interviews

#4
post #3

I tend to ask what I think is a rather simpler question in most interviews: find the sum of the two largest (most positive) numbers in an array of arbitrary integers. Consider the efficiency of your solution for very large arrays. It is amazing how many seemingly knowledgeable, intelligent people cannot do this. And the vast majority of those who do, do it by sorting the array, efficiency be damned. Actually, I'd lik…

I'd expect anyone I interview to be able to do that, kind of like fizzbuzz.

It's okay if they pull out the sort-the-array solution first, but I'd definitely try to get them to improve it.

Re: Life, the Universe and Technical Interviews

#6
post #3

I tend to ask what I think is a rather simpler question in most interviews: find the sum of the two largest (most positive) numbers in an array of arbitrary integers. Consider the efficiency of your solution for very large arrays. It is amazing how many seemingly knowledgeable, intelligent people cannot do this. And the vast majority of those who do, do it by sorting the array, efficiency be damned. Actually, I'd lik…

Solution is just to have two indices into it leapfrogging as they find the next biggest one, right, and sum at the end if they've moved?

Why would you sort?

Re: Life, the Universe and Technical Interviews

#7
post #3

I tend to ask what I think is a rather simpler question in most interviews: find the sum of the two largest (most positive) numbers in an array of arbitrary integers. Consider the efficiency of your solution for very large arrays. It is amazing how many seemingly knowledgeable, intelligent people cannot do this. And the vast majority of those who do, do it by sorting the array, efficiency be damned. Actually, I'd lik…

I have seen plenty of useful code far worse than sorting such an array. IMO, someone missing the 'obvious' choice in an interview question is completly reasonable.

Thinking back how many people verified that the array was non empty and it had more than one element? I call it the toy problem mindset, when coding you consider things deeply but in meetings your looking for roadblocks not optimal solutions.

PS: From a preformace standpoint sorting your array is relativly better than ant of the posted solutions. Even though the article links to a much faster method. Aka there x log x solutions when a log x solution exists.

Re: Life, the Universe and Technical Interviews

#9
post #3

I tend to ask what I think is a rather simpler question in most interviews: find the sum of the two largest (most positive) numbers in an array of arbitrary integers. Consider the efficiency of your solution for very large arrays. It is amazing how many seemingly knowledgeable, intelligent people cannot do this. And the vast majority of those who do, do it by sorting the array, efficiency be damned. Actually, I'd lik…

Solution is just to have two indices into it leapfrogging as they find the next biggest one, right, and sum at the end if they've moved? Why would you sort?

My thoughts exactly. O(n) vs O(nlog(n)). Or even if you don't have formal comp sci experience, it seems intuitive that sorting the entire array (which I specify could be large) just to get the two highest values is overkill.

Want to apply to our full stack developer position?

Edit: Out of curiosity, what would you initialize the two tracking variables to?

Re: Life, the Universe and Technical Interviews

#10
post #3

I tend to ask what I think is a rather simpler question in most interviews: find the sum of the two largest (most positive) numbers in an array of arbitrary integers. Consider the efficiency of your solution for very large arrays. It is amazing how many seemingly knowledgeable, intelligent people cannot do this. And the vast majority of those who do, do it by sorting the array, efficiency be damned. Actually, I'd lik…

I'd expect anyone I interview to be able to do that, kind of like fizzbuzz. It's okay if they pull out the sort-the-array solution first, but I'd definitely try to get them to improve it.

Yes, I agree with this too. And in some ways sorting is a better solution. The code is certainly simpler. That said, once you point out that you need an efficient solution for large data sets, a competent developer should be able to recognize how to do that. Heck, even if they just said, "ok, so you need to loop through it and keep track of the two largest numbers", then messed up the details, that would be better than most of the answers I've seen. (Again, from people with reasonable-looking applications and resumes.)
Post reply on HN